两个相同的@ Html.DropDownList语句正在呈现不同的HTML。第二个工作正常,但是第一个始终返回默认值,无论选择什么。
@Html.DropDownList 语句在以下代码中:
<div class="form-group">
@Html.LabelFor(model => model.UnidadeId, "Unidade", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("UnidadeId", (SelectList)ViewBag.UnddId, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.UnidadeId, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.UnidadeConsumoId, "Unidade de Consumo", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("UnidadeConsumoId", (SelectList)ViewBag.UndConsId, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.UnidadeConsumoId, "", new { @class = "text-danger" })
</div>
</div>
以及呈现的HTML:
<div class="form-group">
<label class="control-label col-md-2" for="UnidadeId">Unidade</label>
<div class="col-md-10">
<select class="form-control" id="UnidadeId" name="UnidadeId">
<option value="1">cx</option>
<option value="2">pc</option>
<option selected="selected" value="3">kg</option>
<option value="4">mt</option>
<option value="5">rl</option>
<option value="6">ml</option>
<option value="8">na</option>
<option value="9">hr</option>
<option value="10">un</option>
<option value="11">lt</option>
</select>
<span class="field-validation-valid text-danger" data-valmsg-for="UnidadeId" data-valmsg-replace="true"></span>
</div>
</div>
</select>
<span class="field-validation-valid text-danger" data-valmsg-for="UnidadeConsumoId" data-valmsg-replace="true"></span>
</div>
</div>
慕哥6287543
相关分类