【发布时间】:2016-12-23 10:37:33
【问题描述】:
所以我已经从我的数据库和从我生成视图的控制器中设置了我的模型和控制器。因此,为了给您一些背景信息,我创建了一个应用程序供用户发布和编辑有关特定服务的评论。我为用户创建了一个“创建”和“编辑”视图来创建评论和/或编辑评论。创建视图中的部分表单组允许用户选择他们想要查看的服务
<div>
<div class="form-group">
@Html.LabelFor(model => model.WellnessService, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("WellnessService", new List<SelectListItem>
{
new SelectListItem() {Text = "Student Wellness Service", Value = "Student Wellness Service"},
new SelectListItem() {Text = "HAICU", Value = "HAICU"},
new SelectListItem() {Text = "Student Counceling", Value = "Student Counceling"},
new SelectListItem() {Text = "DISCHO ( Discrimination and Harassment Office)", Value = "DISCHO"},
new SelectListItem() {Text = "Campus Protection Service (CPS)", Value = "CPS"},
new SelectListItem() {Text = "Disablity Service", Value = "Disability Service"},
}, "Select Wellness Service")
@Html.ValidationMessageFor(model => model.WellnessService, "", new { @class = "text-danger" })
</div>
</div>
</div>
但是在编辑视图中,用户可以根据自己的喜好调整服务的价值。我希望用户仅根据我提供的下拉菜单更改评论的服务名称,而不是输入
<div class="form-group">
@Html.LabelFor(model => model.Rating, htmlAttributes: new {@class = "control-label col-md-2"})
<div class="col-md-10">
@Html.EditorFor(model => model.Rating, new {htmlAttributes = new {@class = "form-control"}})
@Html.ValidationMessageFor(model => model.Rating, "", new {@class = "text-danger"})
</div>
</div>
如果有道理的话:P
我听说你必须在你的模型中设置一个枚举器,但是有可用的指南,这是代码优先 mvc5 而不是数据库优先
【问题讨论】:
标签: c# asp.net-mvc ienumerable