.net 除非指定了数据上下文,否则为什么枚举不被构建

.net 除非指定了数据上下文,否则为什么枚举不被构建,.net,asp.net-mvc,visual-studio,scaffold,.net,Asp.net Mvc,Visual Studio,Scaffold,当我从模型中构建视图时,除非指定数据上下文类,否则我的枚举将被忽略?为什么会这样 这是我的模型: public class customer { public int customerId { get; set; } public Title customerTitle { get; set; } public string CustomerName { get; set; } } public enum Title { Mr, Miss, Mrs, Ms

当我从模型中构建视图时,除非指定数据上下文类,否则我的枚举将被忽略?为什么会这样

这是我的模型:

 public class customer
{
    public int customerId { get; set; }
    public Title customerTitle { get; set; }
    public string  CustomerName { get; set; }
}


public enum Title
{
    Mr, Miss, Mrs, Ms
}  
当我构建一个创建视图并指定一个数据上下文类时,我在视图中得到以下信息:

<div class="form-group">
    @Html.LabelFor(model => model.customerTitle, htmlAttributes: new { @class = "control-label col-md-2" })
    <div class="col-md-10">
        @Html.EnumDropDownListFor(model => model.customerTitle, htmlAttributes: new { @class = "form-control" })
        @Html.ValidationMessageFor(model => model.customerTitle, "", new { @class = "text-danger" })
    </div>
</div>

@LabelFor(model=>model.customertile,htmlAttributes:new{@class=“controllabel col-md-2”})
@EnumDropDownListFor(model=>model.customerTitle,htmlAttributes:new{@class=“form control”})
@Html.ValidationMessageFor(model=>model.customerTitle,“,new{@class=“text danger”})
但是如果我再次构建同一个模型,但是没有数据上下文,枚举就根本不存在了

这就是我指定或不指定数据上下文类的地方


请您提供不同的代码,代码中也包含数据上下文,以便我们可以看到代码中的差异?您是如何搭建的?我为客户搭建了一个创建视图model@Luke,我添加了一个指定数据上下文位置的图像。嗯,指定数据上下文会导致脚手架的行为不同。这是显而易见的。显然,其中一个区别是包含了枚举属性。脚手架就是脚手架,所以如果它不能按你想要的方式工作,你也无能为力。总之,无论如何,您都不应该依赖于脚手架功能。这只是训练轮子。一旦您了解了工作原理,您几乎总是最好只手动添加视图等。