1
How do I validate using Html helper and data Annotation, but without giving post
I mean, ex:
Stringlength(10) While he is typing, go validating this annotation...(among others)
1
How do I validate using Html helper and data Annotation, but without giving post
I mean, ex:
Stringlength(10) While he is typing, go validating this annotation...(among others)
2
Don’t forget to add to which Model
to View
refers: @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")
In the BundleConfig
you need to add the following Bundle
:
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.unobtrusive*",
"~/Scripts/jquery.validate*"));
Browser other questions tagged asp.net-mvc-5
You are not signed in. Login or sign up in order to post.
This validation occurs only when submitting the post, using isValid in the controller
– Rod
This validation is to happen in real time, using the Bundle
– Diego Zanardo
Diego’s answer is correct Rod! unobtrusive validation is done via javascript, it only gives the POST if unobtrusive validation passes! If this is not the case check your web.config and make sure that these 2 keys are enabled: <add key="Clientvalidationenabled" value="true" /> <add key="Unobtrusivejavascriptenabled" value="true" />
– Premiere