2015-04-03 94 views
0

在我的asp.net mvc4應用程序中,例如在創建新項目「cond」時,出現此錯誤「從客戶端檢測到潛在危險的Request.Form值」。 cond是數據庫中具有兩個字段「id_regle」和「cond_txt」的表。 cond_txt字段將具有以下形式的條件「left_side + op + right_side」; op = <,>,== .... 我嘗試了不同的建議,我發現,但他們沒有爲我工作,禁用此驗證。在MVC 4中禁用客戶端驗證提交按鈕

這是視圖 「創造」:

@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") 
} 

這是控制器:

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); 
    } 

我試着在web.config中加入validateRequest = 「假」,但沒有爲我工作 任何建議plz

+0

http://stackoverflow.com/questions/81991/a-potentially-dangerous-request-form-value-was-detected-from-the可能duplivate - 客戶 – 2015-04-03 09:50:18

+0

在哪裏把validateRequest =「false」?在mvc4 asp.net – 2015-04-03 10:14:58

+0

我在web.config中的中嘗試過,但沒有奏效 – 2015-04-03 10:16:52

回答

0

這是什麼爲我工作,我在控制器中添加[ValidateInput(false)] reference

0

您可以使用下面的代碼在控制渲染時禁用客戶端驗證。

@{ Html.EnableClientValidation(false); } 

或試試這個

<%@ Page validateRequest="false" %>