Reputation: 66
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?
Upvotes: 0
Views: 1452
Reputation: 3491
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.
Upvotes: 0
Reputation: 1295
The following page will give you the answer you require. Either create a Html Helper or a partial page
Upvotes: 1
Reputation: 1903
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.
Upvotes: 0