Reputation: 7674
I have 2 action methods:
[HttpGet]
public ActionResult Customize()
{
return View(new CustomizeViewModel { Thing1 = "test", Thing2 = "test" });
}
[HttpPost]
public ActionResult Customize(CustomizeViewModel customizeViewModel)
{
_someService.DoSomething(customizeViewModel);
...
}
My ViewModel looks like:
public class CustomizeViewModel
{
public string Thing1 { get; set; }
public string Thing2 { get; set; }
public string Thing3 { get; set; }
}
In my View, I have a textbox that collects a value for Thing3
and simply shows the values for Thing1
and Thing2
. My problem is, when I POST and enter the POST version of the Customize
method, I only get a value for Thing3
(the one that I typed into the textbox.) Is there any way to get the values I populated in the GET version of the Customize method to carry over? I tried UpdateModel()
but that didn't work.
Upvotes: 1
Views: 628
Reputation: 77536
This is one of the things for which hidden input fields were created. Store the values in there using HiddenFor
in the View and you should be set. The only data that will come along for the ride in the HTTP POST version are form-input elements.
Upvotes: 1