驗證工作的其他輸入類型的文本元素,但不工作的DropDownListFor驗證DropDownListFor不適用於MVC3?
類採購輸入屬性代碼
[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>