Asp.net-Mvc
使用數據註釋渲染 <textarea />
我想為模型中的一個欄位呈現一個文本區域。
我試過申請
[DataType(DataType.MultilineText)]我的領域,但這並沒有成功。目前,我正在手動渲染文本區域,但我更喜歡使用
Html.EditorFor. 有什麼建議?
為什麼不使用:
@Html.TextAreaFor(model => model.YourProperty)EditorFor 助手是一種“智能”助手,它基於屬性的底層類型進行渲染。如果您想強制它呈現特定的 html 輸入類型,請使用其他助手。
[DataType(DataType.MultilineText)]僅當您Html.EditorFor在視圖中使用 helper 時才有效:樣本:
模型
[DataType(DataType.MultilineText)] public string Description { get; set; }看法
Html.EditorFor(m => m.Description)