将下拉列表ID转换为要存储在sql中的文本

时间:2017-11-15 13:04:21

标签: jquery asp.net-mvc model-view-controller

我希望从数据库中恢复的下拉列表中的商店文本,我能够在网站中显示

但现在我只在sql DB中获取id。请提出建议

查看

<div class="form-group">
    <label class="control-label col-sm-3" for="email">Coachings:*</label>
    <div class="col-sm-8">@Html.DropDownListFor(model => model.MainCourseId, new SelectList(Model.MainCourseList, "Key", "Value"), "Select Main Course", new { @class = "form-control", required = "required" })</div>
</div>

控制器

MainCourse = request.MainCourseId.ToString()

1 个答案:

答案 0 :(得分:0)

默认情况下,Html.DropDownListFor()会将所选选项“value”发送给控制器...如果要发送文本,则将课程名称作为值.......

@Html.DropDownListFor(model => model.MainCourseId, new SelectList(Model.MainCourseList, "CourseName", "CourseName"), "Select Main Course", new { @class = "form-control", required = "required" })