【发布时间】:2019-08-30 05:27:05
【问题描述】:
我有一个名为 contract_detail 的模型类,它们是此类中的一个名为 season 的字段我创建了另一个类,并在这个新类中定义了季节字段现在我想在视图中显示新类的所有变量在下拉列表中。
<div class="form-group">
@Html.LabelFor(model => model.Season, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(model => model.Season, new SelectList(Enum.GetValues(typeof(Season)), new { @class = "form-control" })
@*@Html.EditorFor(model => model.Season, new { htmlAttributes = new { @class = "form-control" } })*@
@Html.ValidationMessageFor(model => model.Season, "", new { @class = "text-danger" })
</div>
</div>
//My season class which define field season
public class Season
{
public Season(string value) { Value = value; }
public string Value { get; set; }
public static Season S1 { get { return new Season("2018-2019"); } }
public static Season S2 { get { return new Season("Debug"); } }
public static Season S3 { get { return new Season("Info"); } }
public static Season S4 { get { return new Season("Warning"); } }
public static Season S5 { get { return new Season("Error"); } }
}
【问题讨论】:
标签: c# asp.net asp.net-mvc-4