本文介绍了将枚举绑定到 MVC 4 中的 DropDownList?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我到处都发现将 Enums 绑定到 DropDowns 的常用方法是通过辅助方法,这对于这样一个看似简单的任务来说似乎有点霸道.
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.
在 ASP.Net MVC 4 中将枚举绑定到 DropDownList 的最佳方法是什么?
What is the best way to bind Enums to DropDownLists in ASP.Net MVC 4?
推荐答案
您可以:
@Html.DropDownListFor(model => model.Type, Enum.GetNames(typeof(Rewards.Models.PropertyType)).Select(e => new SelectListItem { Text = e }))
这篇关于将枚举绑定到 MVC 4 中的 DropDownList?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!