我的模型包含一個名爲「longdescription」的字符串字段,得到TinyMCE的編輯器的內容的價值ASP.NET MVC AllowHtml錯誤什麼的,我沒有使用正確
Public class ArticleModel:BaseModel{
[StringLength(8000, ErrorMessage = "Long description must be in 8000 characters or less"), AllowHtml]
public string LongDescription { get; set; }
}
這裏是我的控制器代碼
[HttpPost]
public ActionResult AddEdit(ArticleModel model)
{
string buttonName = Request.Form["Button"];
if (buttonName == "Cancel")
return RedirectToAction("Index");
// something failed
if (!ModelState.IsValid)
{
}
// Update the articles
}
我的問題是,當我使用Request.Form訪問帖子值,它工作正常,沒有拋出「一個潛在危險的....」錯誤,但是當我使用Request.Params [「Button」]時,它扔了那個錯誤。我錯過了什麼?
感謝
更新
對不起答案亞當給了並沒有真正回答我的問題。任何人都可以提供更多建議嗎?
這個答案假定你知道在編譯時所有的表單字段。如果你在運行時生成表單域,你會怎麼做。我有一個例子,我需要在運行時生成未定義數量的表單字段。這工作正常使用Request.Params,直到我想在輸入中允許html。 – ChrisFox