编辑

时间:2017-02-28 21:28:44

标签: c# asp.net-mvc razor html.dropdownlistfor

在编辑期间,我将以下表格中的值ScannerTypes获取到ViewBag中,如下所示

ViewBag.ScannerTypeID = new SelectList(db.ScannerTypes, "ScannerTypeID", "Name", db.ScannerTypes);

对于少数行,ScannerTypeID的值可以是null。如果ScannerTypeIDnull,我希望将默认消息显示为"选择扫描程序类型"否则我想显示所选的名称。这是我的Razor代码

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

不幸的是,对于所有编辑,我收到消息为&#34;选择扫描仪类型&#34;。

0 个答案:

没有答案