开发者

ASP.net MVC how to get the value of the ID field for the list of items? [duplicate]

开发者 https://www.devze.com 2022-12-13 13:16 出处:网络
This question already has answers here: asp.net mvc and linq to entities: how to include text value from IEnumerable<SelectListItem>
This question already has answers here: asp.net mvc and linq to entities: how to include text value from IEnumerable<SelectListItem> (2 answers) Closed 2 years ago.

I have an application, that shows list of items bound to a typed model.

In the list every item has an ID from a lookup table.

How to show the value of the lookup data for each item instead of IDs?

The best way has to link a html dropdownlist to each ID, from where I would be able to choose the appropriate value.

Thanks in advance

Gabr开发者_运维问答ile


Well the first step is to make sure you get all of the values that will be in the DropDownList. You should be able to easily fetch this from your database.

Set the text of the DropDownList items to the text value for the lookup item, and set the value to the ID of those same items.

When creating the DropDownList make sure to set the Selected one to be the option which matches the ID of your modeled data item.

0

精彩评论

暂无评论...
验证码 换一张
取 消