问题描述
我有一个名为的组织,我已经创建了一个枚举类型的typeid整型字段表。在code我可以设置并使用枚举比较typeid的。
using MVC4 Razor and Entityframework 5. I have a table called organisation with a integer TypeID field which i have created an enum type. In the code i can set and compare the typeid using the enum.
public enum OrganisationType : int
{
Company = 1,
Department = 2,
Location = 4
}
然而,当我产生create.cshtml或者使用默认vs2012 MVC 4剃刀模板,或通过mvcscaffolding的NuGet包中同时忽略typeid的领域。我想修改模板,TT,使他们自动生成的。但最初是有可能在dropdownlistfor显示枚举的描述性名称。
However when i generate the create.cshtml either using the default vs2012 mvc 4 razor templates, or the via the mvcscaffolding nuget package both ignore the TypeID field. I was thinking of amending the tt templates so that they are autogenerated. But initially is it possible to display the descriptive name of the enum in a dropdownlistfor.
推荐答案
这是解决方案,它只是一个耻辱,它不是简单的修改TT模板来自动完成这个。
This is the solution, its just a shame that its not simple to modify the TT templates to automate this.
@Html.DropDownListFor(model => model.TypeID, new SelectList(Enum.GetValues(typeof(Models.OrganisationType))))
这显示与文本值dropdowncombo它即公司,部门,地点。
This displays a dropdowncombo with the Textual values in it i.e. company, department, location.
这篇关于在EF5 DropDownListFor枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!