验证适用于其他输入类型的文本元素,但不适用于 DropDownListFor
类购买输入属性代码
[Required]
public string LedgerId { get; set; }
类视图模型代码
PurchaseViewModel purchaseVM = new PurchaseViewModel
{
// PurchaseInput=purchaseInput,
Ledger = uw.LedgerRepository.Get().Select(x => new SelectListItem { Value = x.Id.ToString(), Text = x.LedgerName }),
};
看法
<div class="column">
<div class="labelField">
@Html.LabelFor(model => model.PurchaseInput.LedgerId, "Party")
</div>
<div class="ItemField">
@Html.DropDownListFor(model => model.PurchaseInput.LedgerId, new SelectList(Model.Ledger, "Value", "Text"))
@Html.ValidationMessageFor(model => model.PurchaseInput.LedgerId)
</div>
</div>