I have a drop down list control on a partial view and after posting the form the state of the drop down list control is not maintained
Here is the partial view cshtml co
The following code creates the view model for your next partial view:
TestCriteriaConsolidated combined = new TestCriteriaConsolidated();
combined.testCriteriaResults = test;
You need to set the year on this model:
combined.testCriteria.Year = Request.Form["testCriteria.Year"];
combined.testCriteria.Year
needs to get set with the form value you posted
Try this
[HttpPost]
public ActionResult Results(TestCriteriaConsolidated form)
{
List<TestCriteriaResults> test = new List<TestCriteriaResults>();
test.Add(new TestCriteriaResults { Value1 = "one", Value2 = "one", Value3 = "three", Value4 = "Four" });
test.Add(new TestCriteriaResults { Value1 = "one", Value2 = "two", Value3 = "three", Value4 = "four" });
test.Add(new TestCriteriaResults { Value1 = "one", Value2 = "two", Value3 = "three", Value4 = "four" });
test.Add(new TestCriteriaResults { Value1 = "one", Value2 = "two", Value3 = "three", Value4 = "four" });
test.Add(new TestCriteriaResults { Value1 = "one", Value2 = "two", Value3 = "three", Value4 = "four" });
TestCriteria criteria = new TestCriteria() { Year = form.testCriteria.Year };
TestCriteriaConsolidated combined = new TestCriteriaConsolidated
{
testCriteriaResults = test,
testCriteria = criteria
};
return View(combined);
}
public ActionResult Results()
{
return View(new TestCriteriaConsolidated());
}