我在ASP.NET MVC 3/Razor中使用客戶端驗證(不顯眼)我通過使用Html.EditorFor和指定DataType.MultilineText來獲得它在<textarea>
上的工作,但不應該Html.TextAreaFor也有客戶端驗證?Html.TextBoxFor/Html.TextAreaFor和Html.EditorFor(與[DataType(DataType.MultilineText)]之間的客戶端驗證區別
[Required(ErrorMessage = "Foo")]
public string Message { get; set; }
// Does add client-side validation
@Html.TextBoxFor(m => m.Message)
// Does NOT add client-side validation
@Html.TextAreaFor(m => m.Message)
[Required(ErrorMessage = "Foo")]
[DataType(DataType.MultilineText)]
public string Message { get; set; }
// Does add client-side validation (and multiline)
@Html.EditorFor(m => m.Message)
// Does NOT add client-side validation
@Html.TextAreaFor(m => m.Message)
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />