绑定枚举在MVC 4一个DropDownList? [英] Binding an Enum to a DropDownList in MVC 4?
问题描述
我一直在寻找全国各地的绑定来枚举下拉式菜单中常见的方式是通过辅助方法的地方,这似乎对于这样一个看似简单的任务有点霸道。
I've been finding all over the place that the common way to bind Enums to DropDowns is through helper methods, which seems a bit overbearing for such a seemingly simple task.
什么是MVC 4绑定枚举到DropDownLists在ASP.Net的最佳方式?
What is the best way to bind Enums to DropDownLists in ASP.Net MVC 4?
推荐答案
我觉得这是对只(干净)的方式,这是一个遗憾,但至少也有少数的选择了。我建议有一个看这个博客:<一href=\"http://paulthecyclist.com/2013/05/24/enum-dropdown/\">http://paulthecyclist.com/2013/05/24/enum-dropdown/
I think it is about the only (clean) way, which is a pity, but at least there are a few options out there. I'd recommend having a look at this blog: http://paulthecyclist.com/2013/05/24/enum-dropdown/
对不起,它太长复制到这里,但要点是,他创造了这个新的HTML helper方法。
Sorry, it's too long to copy here, but the gist is that he created a new HTML helper method for this.
所有的源$ C $ C可在 GitHub上。
All the source code is available on GitHub.
这篇关于绑定枚举在MVC 4一个DropDownList?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!