c# - DropdownList Not Showing Selected Item -
i creating page edit non-conformance reports. page takes in model follows:

on page, trying show dropdown list current value of faultcode property pre-selected. however, not working. instead have stripped basics , tried hard code pre-selected value, follows:
@{ var faultcodelist = new list<selectlistitem> { new selectlistitem { text = "internal damage", value = "internal damage" }, new selectlistitem { text = "customer problem", value = "customer problem" }, new selectlistitem { text = "incorrect material supplied", value = "incorrect material supplied" }, new selectlistitem { text = "received material damaged", value = "received material damaged" }, new selectlistitem { text = "no test certificate supplied", value = "no test certificate supplied" }, new selectlistitem { text = "other", value = "other", selected = true} }; } @html.dropdownlist("faultcode", faultcodelist) this still not work. however, if change name of field other faultcode - i.e faultcode2 - works fine!
why seeing strange behaviour? on same page have dropdown lists other fields, , working perfectly...
@html.dropdownlist("faultcode", new selectlist(faultcodelist, "value", "text","other")) you need bind selectlist list, last parameter can mention selected value "other".
Comments
Post a Comment