开发者

How do you preserve the viewstate while using strongly typed views in asp MVC 2?

I have an ActionResult returning from a strongly typed view where I manually validate some conditions, pass in an error message, but would like to preserve the users responses.

Since my View is strongly typed, I am calling it like this:

return View("PrincipalInvestigatorForm", new SmartFormViewModel(sections, questions));

My problem though, is that the error message is displayed but开发者_Go百科 all the users data is wiped. How do I preserve the "ViewState" in MVC? Is there an easy way?


What does your action looks like? I'm using something like this:

[HttpPost]
public ActionResult Edit(MyModel model)
{
    if (ViewData.ModelState.IsValid)
    {
        // Whatever...
    }
    else
    {
        return View("Editmodel", model)
    }
}


Your best bet is to re-populate the SmartFormViewModel model based on the form information.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜