ASP.NET MVC 4 ViewModel with DropDownList data

后端 未结 4 1866
生来不讨喜
生来不讨喜 2020-12-14 23:35

I\'m using @html.EditorFor to render my model in edit mode, and a dropdownlist is not rendered.

Here\'s my ViewModel:

     public class          


        
4条回答
  •  太阳男子
    2020-12-14 23:50

    Unfortunately, there is no built in support for drop down lists in the editor for templates. You can either write your own editor template, or use the html helper method @Html.DropDownListFor() in your view.

    Darin Dimitrov's answer to this question can walk you through the process of building an editor template for drop down lists, if you are so inclined.

    The quickest way to get this working would be to do this in your view:

    @Html.EditorFor(model => model.NoClaimsDegree)
    @Html.EditorFor( model => model.VehicleValue )
    @Html.EditorFor( model => model.EngineCapacity )
    @Html.DropDownListFor( model => model.VehicleMake, Model.VehicleMakeList, "Select a make" )
    

提交回复
热议问题