Question

Is there a way to pass ModelState to RedirectToAction without use of TempData?

UPDATED

I have the following actions:

public ActionResult Index()
{
    var model = SettingsService.GetSettings();
    return View(model);
}

[HttpPost]
public ActionResult Update(Settings model)
{
     if (ModelState.IsValid)
     {
         SettingsService.UpdateSettings(model);
     }

     return RedirectToAction("Index");
}

The model has server validation errors. I would like to show errors after redirection to Index.

The applications is in cloud and it has at least two WebRoles, each machine has it's own session, thus I cannot use TempData (which uses Session).

Was it helpful?

Solution

If ability to use Session is blocker for you, it may be fixed. With a little of configuration you can use Session State Provider for Windows Azure. As far as it is shared storage it is stateless, your WebRoles remains stateless as well.

Here is where you can get all the instructions: http://msdn.microsoft.com/en-us/library/windowsazure/gg185668.aspx

OTHER TIPS

You could try passing the ModelState as a parameter or at least make a copy of it or of the properties you need:

RedirectToAction("MyAction", 
   new System.Web.Routing.RouteValueDictionary() { { "modelState", ModelState } });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top