我正在使用MVC4。MVC 4客戶端驗證將顯示在對話框中
我有一個ViewModel已經裝飾了[Required()]
驗證屬性。
當表單被提交時,客戶端驗證被激發並顯示在線(使用驗證摘要),所以一切都按照它應該的方式工作。
如何在對話框中顯示驗證而不是在線?
下面是從MVC 4互聯網應用模板
public class RegisterModel
{
[Required]
[Display(Name = "User name")]
public string UserName { get; set; }
[Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[DataType(DataType.Password)]
[Display(Name = "Confirm password")]
[Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
public string ConfirmPassword { get; set; }
}
@model MvcApplication2.Models.RegisterModel
@{
ViewBag.Title = "Register";
}
<hgroup class="title">
<h1>@ViewBag.Title.</h1>
<h2>Create a new account.</h2>
</hgroup>
@using (Html.BeginForm()) {
@Html.AntiForgeryToken()
@Html.ValidationSummary()
<fieldset>
<legend>Registration Form</legend>
<ol>
<li>
@Html.LabelFor(m => m.UserName)
@Html.TextBoxFor(m => m.UserName)
</li>
<li>
@Html.LabelFor(m => m.Password)
@Html.PasswordFor(m => m.Password)
</li>
<li>
@Html.LabelFor(m => m.ConfirmPassword)
@Html.PasswordFor(m => m.ConfirmPassword)
</li>
</ol>
<input type="submit" value="Register" />
</fieldset>
}
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
所以,當我點擊無需在文本框中的所有數據提交按鈕的代碼示例,在一個驗證摘要頂部顯示錯誤消息。
目前我正在使用Kendo ui對話框來顯示服務器返回的所有錯誤。所以我試圖做的是統一錯誤信息,以便它們都以類似的方式顯示。
目前我只是想知道如何連接到客戶端驗證,這樣我就可以調用與錯誤的詳細信息劍道UI對話框..
感謝