MVC3 Drop Down List Control does not keep State, Why?

前端 未结 2 1368
臣服心动
臣服心动 2021-01-24 01:56

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

2条回答
  •  甜味超标
    2021-01-24 02:52

    combined.testCriteria.Year needs to get set with the form value you posted

    Try this

    [HttpPost]
        public ActionResult Results(TestCriteriaConsolidated form)
        {
            List test = new List();
            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());
        }
    

提交回复
热议问题