Search code examples
jqueryasp.net-mvcasp.net-mvc-3jquery-validate

ASP.NET MVC 3 validation on blur


How do I call the validation when the textbox looses focus? Eg.

@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)

    <div class="editor-label">
        @Html.LabelFor(model => model.Name)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.Name)
        @Html.ValidationMessageFor(model => model.Name)
    </div>
}

public class RegisterViewModel
{
    [Required]
    [StringLength(5)]
    public string Name { get; set; }
}

Also, How can I check if the name exist already by calling an action?


Solution

  • remote validation is a new feature of MVC 3: http://msdn.microsoft.com/en-us/library/gg508808(v=vs.98).aspx