简体   繁体   English

ASP.net MVC 4下拉列表

[英]ASP.net MVC 4 Drop Down List

I am a bit lost on the concept of drop down list in MVC 4. 我对MVC 4中下拉列表的概念有点迷茫。

I have to models 我要模特儿

Gender - int ID - string Title 性别 - int ID - 字符串标题

User -string FirstName - Gender -... User -string FirstName - 性别-...

I am bit unsure how to tackle it, to keep it clean and simple. 我有点不确定如何解决它,保持它干净和简单。

For the type in my class users, should it be Gender because its the name of the table or should it be this IEnumerable? 对于我的类用户中的类型,它应该是Gender,因为它是表的名称还是应该是这个IEnumerable?

If its if so i am missing other things? 如果它如果是这样我错过了其他的东西?

Also should i provide something specific to the controllers? 我还应该提供特定于控制器的东西吗? or how do I display the dropdownlist in C# MVC 4 Razor code. 或者如何在C#MVC 4 Razor代码中显示下拉列表。

Have a look at the SelectList class http://msdn.microsoft.com/en-us/library/system.web.mvc.selectlist%28v=vs.108%29.aspx 看一下SelectListhttp://msdn.microsoft.com/en-us/library/system.web.mvc.selectlist%28v=vs.108%29.aspx

This goes in your model, then you can create a dropdownlist like this: 这在您的模型中,然后您可以创建这样的下拉列表:

@Html.DropDownList("GenderId", Model.Genders)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM