.net - Setting selected value in SelectList isn't working using DropDownListFor -


After text "itemprop =" text ">

I'm creating a selectList for a drop

  public class EditDeviceViewModel {public selectList DeviceTypeList {Received; Set; } Public Utility Type Type {Received; Set; } Public EditDeviceViewModel (device device, IEnumerable & lt; DeviceType & gt; DeviceTypes) {... DeviceTypeList = new selectList (DeviceTypes.OrderBy (t = & gt; t.Type), "id", "type", device. DeviceType.ID); SelectedDeviceType = device.DeviceType.ID; }}   

So in my opinion I am using HTML Assistant

  @ Html.DropDownListFor (model = & gt; create a drop down; model .SelectedDeviceType, Model.DeviceTypeList, new {id = "devicetypelist"})   

When the view is provided, the value selected by me when selecting selectList initialising is not. What am i doing wrong

After the

dropdown will use the value of the list SelectedDeviceType property as the selected value What you can do is set the property value when you build the model

  public class EditDeviceViewModel {get the public selectList DeviceTypeList { Set; } Public Utility Type Type {Received; Set; } Public EditDeviceViewModel (device device, IEnumerable & lt; DeviceType & gt; DeviceTypes) {... DeviceTypeList = New SelectList (DeviceTypes.OrderBy (t = & gt; T. type), "id", "type"); SelectedDeviceType = device.DeviceType.ID; ...}}    

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -