How to update model?

Posted by Alexander Efimov on Stack Overflow See other posts from Stack Overflow or by Alexander Efimov
Published on 2011-01-16T20:50:47Z Indexed on 2011/01/17 1:53 UTC
Read the original article Hit count: 632

Filed under:
|

Hi, guys. I have an ASP.NET MVC page where the model is being edited. On each action executing I have a new controller, so I don't get an updated model. I'm saving a model instance into Session["MyModelKey"]. But every time an action is executed, I have unmodified instance there even if I have changed values in textboxes which were created like this:

@Html.LabelFor(model => model.EMail) @Html.TextBoxFor(model => model.EMail) @Html.LabelFor(model => model.Country) @Html.TextBoxFor(model => model.Country) @Html.ActionLink("MyAction", "MyController")

Controller:

public class MyController : Controller
{
    public ActionResult MyAction()
    {
       //Every time this action is executed - I have a new controller instance
       //So I have null in View.Model
       //I get Session["MyModelKey"] here, 
       //But the model instance properties are not updated 
       //even though I have updated E-mail and Country properties of the model in the UI
    }
}

So, how can I get an updated model?

Thanks in advance.

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about asp.net-mvc-3