During Edit I am getting the values form table ScannerTypes as follows into ViewBag as follows
ViewBag.ScannerTypeID = new SelectList(db.ScannerTypes, "ScannerTypeID", "Name", db.ScannerTypes);
For few rows the value of ScannerTypeID
could be null
. If the ScannerTypeID
is null
, I want to show default message as "Select Scanner Type" else I want to show the selected Name. Here is my Razor code
<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>
Unfortunately for all edit I am getting messages as "Select Scanner Type".