mvc html编辑器,MVC3 Html编辑器助手显示旧模型值
使用HTML編輯器(如HTML.EditorFor()或HTML.DisplayFor())時,如果嘗試修改或更改控制器操作中的模型值,除非刪除模型的ModelState,否則不會看到任何更改你要改變的財產。
雖然@Mark是正確的,但沒有單獨的控制器操作(但您通常會這樣做)并且您不需要重定向到原始操作。
e.g。 - 調用ModelState.Remove(modelPropertyName)...
public ActionResult Index (Models.FormField model=null)
{
ModelState.Remove("text");
model.text += "_changed";
return View(model);
}
如果你想為GET和POST分別采取行動(推薦),你可以做......
public ActionResult Index ()
{
Models.FormField model = new Models.FormField(); // or get from database etc.
// set up your model defaults, etc. here if needed
return View(model);
}
[HttpPost] // Attribute means this action method will be used when the form is posted
public ActionResult Index (Models.FormField model)
{
// Validate your model etc. here if needed ...
ModelState.Remove("text"); // Remove the ModelState so that Html Editors etc. will update
model.text += "_changed"; // Make any changes we want
return View(model);
}
總結
以上是生活随笔為你收集整理的mvc html编辑器,MVC3 Html编辑器助手显示旧模型值的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2021年江西省副高考试成绩查询,江西省
- 下一篇: vue前端 html,Vue.js v-