I have a HttpGet
route called EmailOptions()
and a HttpPost
route also called EmailOptions(OptionsVm emailOptions)
. At this point, they are returning a view with the same name (EmailOptions.cshtml
) that has a OptionsVm
as it's view model. The OptionsVm
contains a domain object that is a few boolean properties as well as a string used to display a message.
Once I set some of the OptionsVm
's domain object bools to true and post to the EmailOptions(OptionsVm emailOptions)
, I set a string to have a simple message and I reset the domain object to a brand new domain object (so anything that was set as true should revert back to false).
What I expect to see is the same page as before, with the bool (checkboxes) unchecked with the only change being there is a string with a message to be displayed. However, while it does set the page with the new string value, the bool checkboxes retain their previous checked state from before and. I know that this does go to the correct post route (the string gets set with the new value after all), I just do not understand why the domain model seems to retain it's previous values, especially as I am explicitly setting the domain model to a new domain model.
My view seems to be caching? But that doesn't make sense.. Anyone have an idea why this is happening?
Some code:
// controller
public class AController : Controller
{
...
public ActionResult EmailOptions()
{
...
return View(
new OptionsVm {
DomainObj = new DomainObj()
}
)
}
[HttpPost]
public ActionResult EmailOptions(OptionsVm vm)
{
... // don't do anything with the actually passed in OptionsVm
return View(
new OptionsVm {
DomainObj = new DomainObj(),
StringContent = "some message"
}
)
}
}
// viewmodel
public class OptionsVm
{
public BooleanObjs DomainObj { get; set; }
public string MessageSometimes { get; set; }
}