How to bind drop down in asp.net mvc 5
Microsoft Net Framework

How to bind drop down in asp.net mvc 5 ?

Problem:

I have a web form, i want to show dropdown in that page, i want to fill the dropdown values from database.

Solution.

1-Code that will return list of user types from database.

 

 var itemss = Model.GetBuyerTypesResult;

 

                List<SelectListItem> myoptions=new List<SelectListItem>();

                foreach (var item in itemss)

                {

                    myoptions.Add(new SelectListItem { Value = item.userTypeID.ToString(), Text = item.userName });

                }

2-Write code in html view as

                                        @Html.DropDownList("CustomerType", (IEnumerable<SelectListItem>)myoptions)

 

 

Share This with your friend by choosing any social account


Upcoming Articles
You may also read following recent Post
Copyright Future Minutes © 2015- 2024 All Rights Reserved.   Terms of Service  |   Privacy Policy |  Contact US|  Pages|  Whats new?
Update on: Dec 20 2023 05:10 PM