MVC DropDownListFor not selecting value from model

后端 未结 6 1261
逝去的感伤
逝去的感伤 2020-12-05 11:42

I have read through this question ASP.NET MVC DropDownListFor not selecting value from model and answer but I don\'t know the solution to my problem.

This is my vi

6条回答
  •  情深已故
    2020-12-05 12:14

    In my opinion one item of the ViewBag.ForeignLanguages should have Selected property set to true. DropDownListFor method select item based on ModelState. Here you have source code of DropDownListFor method an there is something like:

    object defaultValue = (allowMultiple) ? htmlHelper.GetModelStateValue(fullName, typeof(string[])) : htmlHelper.GetModelStateValue(fullName, typeof(string));
    

    And if that value is null then selected value is retrieved from Selected property

提交回复
热议问题