0

In one of my page, When user click submit button all of my controls "Required" message will appear in "Validation summary". Instead of showing all of these messages in the validation summary, I just want to display a single error message, which says "please fill all of these fields". example:

Instead of

<pre>
    <ul>
      <li>First Name required</li>
      <li>Last Name required</li>
      <li>Middle Name required</li>
    </ul>
</pre>

I want something like this:

<pre>
    <ul>
        <li>All fields are required</li>
    </ul>
</pre>

How can we display such message in client side?

3 Answers 3

1

The following page will give you the answer you require. Either create a Html Helper or a partial page

Custom Validation Summary

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

1 Comment

Actually I want some solution with Jquery validation or jquery unobtrusive validation. So that, I can handle it in client itself
0

Try This

[HttpPost]
        public ActionResult SomeAction(SomeModel model)
        {
            if (ModelState.IsValid)
            {
                return View(model);
            }
            ModelState.Clear();
            ModelState.AddModelError("", "All fields are required");
            return View(model);
        }

if your are doing validation at server side.

1 Comment

can you please show me some code snap how you are doing validation at client side..
0

Off the top of my head I can think of two approaches.

One, try using jQuery validator groups. It allows you to create a group of fields for which one error message will appear.

Two, write your own custom attribute to handle both server and client side validation. This answer provides a complete example of how to do this.

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.