Hello...I am using ckeditor in my mvc5 application...when i trying to modify data from "Edit View",it get the data from database but when i trying to save modified data it can not save..it give the error to save...plz help
piece of Edit view
@Html.LabelFor(model => model.Question1, "Question", htmlAttributes: new { @class = "control-label col-md-2" })
@Html.TextAreaFor(model => model.Question1, new { @class = "ckeditor" })
@Html.ValidationMessageFor(model => model.Question1, "", new { @class = "text-danger" })
thank u
Sanjay SabariyaRank #2,262 · 623 reputationPosted May 25, 2015, 9:57 PM EDT
Sanjay SabariyaRank #2,262 · 623 reputationPosted May 25, 2015, 10:05 PM EDT
shervin salimian86 reputationPosted Feb 8, 2018, 4:30 AM EST
Sanjay SabariyaRank #2,262 · 623 reputationPosted May 25, 2015, 9:02 PM EDT
PrakashRank #6,639 · 260 reputationPosted May 25, 2015, 9:14 PM EDT
Exception: A potentially dangerous Request.Form value was detected from the client (Question1="
A coil havi
").Controller: Question
Action: Edit
Sanjay SabariyaRank #2,262 · 623 reputationPosted May 25, 2015, 9:35 PM EDT
PrakashRank #6,639 · 260 reputationPosted May 25, 2015, 9:40 PM EDT
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Question question = db.Questions.Find(id);
if (question == null)
{
return HttpNotFound();
}
ViewBag.Chapter = new SelectList(db.Chapters, "Id", "Name", question.Chapter);
return View(question);
}
// POST: Question/Edit/5
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit([Bind(Include = "Id,Chapter,Question1,Answer_A,Answer_B,Answer_C,Answer_D,Answer_E,Explanation,Correct_Answer,Difficulty,Sequence")] Question question)
{
if (ModelState.IsValid)
{
db.Entry(question).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
ViewBag.Chapter = new SelectList(db.Chapters, "Id", "Name", question.Chapter);
return View(question);
}
view code
@model ExamAssist10.Question
@{
ViewBag.Title = "Edit";
}
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.Id)
@Html.LabelFor(model => model.Sequence, "Sequence No.", htmlAttributes: new { @class = "control-label col-md-2" })
@Html.EditorFor(model => model.Sequence, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Sequence, "", new { @class = "text-danger" })
@Html.LabelFor(model => model.Chapter, "Chapter Name", htmlAttributes: new { @class = "control-label col-md-2" })
@Html.DropDownList("Chapter", null, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Chapter, "", new { @class = "text-danger" })
@Html.LabelFor(model => model.Question1, "Question", htmlAttributes: new { @class = "control-label col-md-2" })
@* @Html.TextAreaFor(model => model.Question1, new { @class = "form-control" })*@
@*@Html.TextAreaFor(model => model.Question1, new { @class = "ckeditor" })*@
@Html.Raw(@Html.TextAreaFor(model => model.Question1, new { @class = "ckeditor" }))
@Html.ValidationMessageFor(model => model.Question1, "", new { @class = "text-danger" })
@Html.LabelFor(model => model.Answer_A, "Answer_A", htmlAttributes: new { @class = "control-label col-md-2" })
@* @Html.EditorFor(model => model.Answer_A, new { htmlAttributes = new { @class = "form-control" } }) *@
@Html.TextAreaFor(model => model.Answer_A, new { @class = "ckeditor" })
@Html.ValidationMessageFor(model => model.Answer_A, "", new { @class = "text-danger" })
@Html.LabelFor(model => model.Answer_B, "Answer_B", htmlAttributes: new { @class = "control-label col-md-2" })
@Html.TextAreaFor(model => model.Answer_E, new { @class = "ckeditor" })
@Html.ValidationMessageFor(model => model.Answer_B, "", new { @class = "text-danger" })
@Html.LabelFor(model => model.Answer_C, "Answer_C", htmlAttributes: new { @class = "control-label col-md-2" })
@Html.TextAreaFor(model => model.Answer_C, new { @class = "ckeditor" })
@Html.ValidationMessageFor(model => model.Answer_C, "", new { @class = "text-danger" })
@Html.LabelFor(model => model.Answer_D, "Answer_D", htmlAttributes: new { @class = "control-label col-md-2" })
@Html.TextAreaFor(model => model.Answer_D, new { @class = "ckeditor" })
@Html.ValidationMessageFor(model => model.Answer_D, "", new { @class = "text-danger" })
@Html.LabelFor(model => model.Answer_E, "Answer_E", htmlAttributes: new { @class = "control-label col-md-2" })
@Html.TextAreaFor(model => model.Answer_E, new { @class = "ckeditor" })
@Html.ValidationMessageFor(model => model.Answer_E, "", new { @class = "text-danger" })
@Html.LabelFor(model => model.Explanation, "Explanation", htmlAttributes: new { @class = "control-label col-md-2" })
@Html.TextAreaFor(model => model.Explanation, new { @class = "ckeditor" })
@Html.ValidationMessageFor(model => model.Explanation, "", new { @class = "text-danger" })
@Html.LabelFor(model => model.Correct_Answer, "Correct_Answer", htmlAttributes: new { @class = "control-label col-md-2" })
@Html.EditorFor(model => model.Correct_Answer, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Correct_Answer, "", new { @class = "text-danger" })
@Html.LabelFor(model => model.Difficulty, "Difficulty", htmlAttributes: new { @class = "control-label col-md-2" })
@Html.EditorFor(model => model.Difficulty, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Difficulty, "", new { @class = "text-danger" })
}
@Html.ActionLink("Back to List", "Index")
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts