1

I got many [Required] fields in my model.

And, in traditional MVC way, I will add @Html.ValidationMessageFor() for each required textbox.

Then, if user doesn't type anything for 5 textboxes, 5 message will show up in the UI.

My question is: can I show just one message saying Please fill mandatory fields in the UI instead of showing the message everywhere like Name is required, Address is required...?

and I need this to be validate on Client Side, without post form back to server

2
  • not a duplicate of stackoverflow.com/questions/7935568/…, going with Aaron's answer. Commented Nov 28, 2012 at 5:21
  • 1
    Not really - that was regarding client side validation with jQuery. Commented Nov 28, 2012 at 5:23

2 Answers 2

3

You might want to look at ValidationSummary - http://msdn.microsoft.com/en-us/library/system.web.mvc.html.validationextensions.validationsummary(v=vs.108).aspx - Returns an unordered list (ul element) of validation messages that are in the ModelStateDictionary object. You can override the message like so:

@Html.ValidationSummary(true, "Invalid form")

Source https://stackoverflow.com/a/4924494/201648

Sign up to request clarification or add additional context in comments.

2 Comments

thanks, but I need it to be done on client side, without a post to the server.
Ah! I have just been hooking into my $(#yourFormName).submit(... event and using return false in the function to stop the submit (api.jquery.com/submit) with custom jQuery, or using jQuery validators docs.jquery.com/Plugins/Validation/validate. A method I like for validating a group of fields is to create a controller which eturns a JSON object and send an AJAX request from the page.codeproject.com/Articles/216439/…. Also have a look at bradwilson.typepad.com/blog/2010/10/….
0

You can use @Html.ValidationSummary:

@Html.ValidationSummary(true, "Please fill mandatory fields")

If you also want to include a list of property specific errors use:

@Html.ValidationSummary(false, "Please fill mandatory fields")

Comments

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.