I’m having a little trouble with something.
I have an HttpGet method like this:
[HttpGet]
public ActionResult Form()
{
MyModel model = new MyModel();
model.something = "hi";
return View(model);
}
In my model:
public string something { get; set; }
[Display(Name="Something Else:")]
public string somethingelse { get; set; }
And in my view i have a form:
@model Path.To.Models.MyModel
@Html.TextBoxFor(model => model.somethingelse)
<input type="submit" value="Submit" />
The problem is after the form is submitted, model.something is coming back as null instead of what I expect, which is “hi”
Here’s my HttpPost
[HttpPost]
public ActionResult Form(MyModel model)
{
// model.somethingelse equals the form value, which is right
// model.something is null, instead of what I expect - "hi"
return View(model);
}
Can anyone help me with this? I need to get the data from the GET to the POST after the form submission, but it’s coming back null.
Thanks
you have to put the “unchanged values” in hidden fields in your view
or it won’t be passed !