开发者

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

开发者 https://www.devze.com 2023-01-03 08:54 出处:网络
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.

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

精彩评论

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