0

I have a form that i want to validate ( show validation summary, show validation properties error messages and support jquery client validation ). Validation summary appears, validation properties error messages appears but when i add

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

for client side validation i get the client validation, i get the validation properties error messages but the validation summary does not appear any more. What am i missing?

1 Answer 1

5

2 things to verify:

  1. The Html.ValidationSummary helper call must be inside the <form>
  2. You must pass false as argument: @Html.ValidationSummary(false)

Example:

@model MyViewModel

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

@using (Html.BeginForm())
{
    @Html.ValidationSummary(false)
    <div>
        @Html.LabelFor(x => x.Foo)    
        @Html.EditorFor(x => x.Foo)
    </div>
    <button type="submit">OK</button>
}
Sign up to request clarification or add additional context in comments.

2 Comments

1. it is inside <from> tag 2. it works but i don't want to see property errors. is there any way?
@gigi, no, of course not. Only properties decorated with validation attributes are capable of emitting HTML5 data-* attributes that are used by unobtrusive validation. Don't expect the client to be able to generate javascript validation for the server side controls that you are performing inside your controller action.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.