ASP.NET MVC - Populate a drop down list

前端 未结 2 1160
执念已碎
执念已碎 2020-12-31 20:35

I\'m new to ASP.NET MVC. I\'m trying to figure out how create a basic drop down list from values in my database. In ASP.NET web forms, I know I can load a drop down list lik

2条回答
  •  时光说笑
    2020-12-31 21:00

    In MVC2, use <%=Html.DropListFor(x => x.MemberName, Model.DropListItems)%> in your view and in your controller you populate DropListItems with a new SelectList containing the items from the database.

    I belive that the Nerd Dinner-sample includes this, and if you're new to MVC you should really really go through and create the Nerd Dinner app, because you learn so much from it, even if you plan to not use what they use.

提交回复
热议问题