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-