以下是我在控制器中的内容:
IList<LocationInFacility> locs = LocationsInFacility(custCodeID);
ViewData["LocationsInFacility"] = new SelectList(locs, "ID", "Name", "DL");
以下是观点:
<label>Location in Facility</label>
<%= Html.DropDownList
("LocationsInFacility",(SelectList)ViewData["LocationsInFacility"]) %>
这是html输出,我希望选择“DL”,但不是:
<select id="LocationsInFacility" name="LocationsInFacility">
<option value="">-- Select a Location in Facility --</option>
<option value="DL">DELI</option>
<option value="BK">BAKERY</option>
</select>
为什么没有选择“DL”?我做错了什么?
答案 0 :(得分:1)
解决方案是将Html.DropDownList更改为:
<%= Html.DropDownList("LocationsInFacility") %>
答案 1 :(得分:-2)
DL是LocationsInFacility数据中的字符串吗?如果不是,您可能需要传递值,而不是ToString等效值