In my asp.net mvc4 app, I get this error "A potentially dangerous Request.Form value was detected from the client" for example when creating a new item "cond". cond is a table in the database with two fields "id_regle" and "cond_txt". The cond_txt fields will have conditions with the following form "left_side+op+right_side"; op= <, >, == .... I tried different suggestions that I found, but non of them worked for me to disable this validation.
This is the view "create":
@model MvcApplication3.cond
@{
ViewBag.Title = "Create";
}
<h2>Create</h2>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>cond</legend>
<div class="editor-label">
@Html.LabelFor(model => model.cond_txt)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.cond_txt)
@Html.ValidationMessageFor(model => model.cond_txt)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.id_regle, "regle")
</div>
<div class="editor-field">
@Html.DropDownList("id_regle", String.Empty)
@Html.ValidationMessageFor(model => model.id_regle)
</div>
<p>
<input type="submit" value="Create" class="cancel" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
And this is the controller:
public ActionResult Create()
{
ViewBag.id_regle = new SelectList(db.regle, "id", "action");
return View();
}
//
// POST: /Default2/Create
[HttpPost]
public ActionResult Create(cond cond)
{
if (ModelState.IsValid)
{
db.cond.AddObject(cond);
db.SaveChanges();
return RedirectToAction("Index");
}
ViewBag.id_regle = new SelectList(db.regle, "id", "action", cond.id_regle);
return View(cond);
}
I've tried adding validateRequest="false" in the web.config, but that didn't work for me Any suggestions plz