Validate without giving post with html helper asp.net mvc

1

How do I validate using Html helper and data annotation, but without posting

That is, eg:

StringLength (10) While he is typing, go validating this anotation ... (among others)

    
asked by anonymous 20.08.2014 / 02:45

1 answer

2

Do not forget to add which Model to View refers to: @model Dominio.Categoria

[View]
@model Dominio.Categoria

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)
    <div class="editor-label">
        @Html.LabelFor(model => model.Nome)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.Nome)<br />
        @Html.ValidationMessageFor(model => model.Nome)
    </div>
    <div>
        <button type="submit" class="btn btn-success">Salvar</button>
    </div>
}
@Scripts.Render("~/bundles/jqueryval")

No BundleConfig you need to add the following Bundle :

bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
       "~/Scripts/jquery.unobtrusive*",
       "~/Scripts/jquery.validate*"));
    
20.08.2014 / 02:55