欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程语言 > c/c++ >内容正文

c/c++

mvc html编辑器,MVC3 Html编辑器助手显示旧模型值

发布时间:2025/4/17 c/c++ 31 豆豆
生活随笔 收集整理的这篇文章主要介绍了 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编辑器助手显示旧模型值的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。