返回修改后的视图模型查看 [英] Return a modified viewModel to view
本文介绍了返回修改后的视图模型查看的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要做的是这样的:
[HttpPost]
公众的ActionResult指数(富富)
{
foo.Name =修改; 返回查看(富);
}
但是当我的观点呈现出来,它总是有旧值!我要如何回报?我必须清除的ModelState每次?
我的观点:
@model MvcApplication1.Models.Foo
@using(Html.BeginForm())
{
@ Html.TextBoxFor(M = GT; m.Name)
@ Html.TextBoxFor(M = GT; m.Description) <输入类型=提交值=发送/>
}
解决方案
我想这可能是正常现象,因为正常的情况下,您发回同型号的观点是当模型有错误。
请参阅:<一href=\"http://blogs.msdn.com/b/simonince/archive/2010/05/05/asp-net-mvc-s-html-helpers-render-the-wrong-value.aspx\" rel=\"nofollow\">http://blogs.msdn.com/b/simonince/archive/2010/05/05/asp-net-mvc-s-html-helpers-render-the-wrong-value.aspx
I wanna do something like this:
[HttpPost]
public ActionResult Index(Foo foo)
{
foo.Name = "modified";
return View(foo);
}
but when my view is rendered, it always has the old values! How can I modify and return? Must I clear the ModelState everytime?
My view:
@model MvcApplication1.Models.Foo
@using (Html.BeginForm())
{
@Html.TextBoxFor(m => m.Name)
@Html.TextBoxFor(m => m.Description)
<input type="submit" value="Send" />
}
解决方案
I think this might be expected behavior because the "normal" scenario where you send back the same model to the view is when the model has errors.
这篇关于返回修改后的视图模型查看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文