Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在我的视图模型中,如果有:
List<Car>
其中汽车有一个ID和一个名字。我想使用创建一个下拉框
Html.DropDownListFor()
什么是最好的连接方式,因为我希望项目的值是 ID,显示是汽车的名称。
你的视图模型中有什么,
显示您想要使用的列表
<%= Html.DropDownList("DropDownName", new SelectList(yourListOfCar, "Id", "Name"))%>
所以如果你想使用 DropDownListFor,你会使用是这样的
<%= Html.DropDownList(model => model.IdCar, new SelectList(yourListOfCar, "Id", "UserName"))%>
其中模型是您的视图模型