Change text of ValidationSummary C# razor MVC

527 Views Asked by At

I am using ValidationSummary to show errors after submit login action on my login page.

There are two different errors to show.

1) Username and password invalid

or

2) You are not allowed to access this feature

The thing is that I want to change the text of the ValidationSummary. I don't want to add errors as bullet points (this is done adding errors to ModelState using ModelState.AddModelError).

How can I achieve this? Change the error message of the ValidationSummary?

Thanks!

1

There are 1 best solutions below

1
Jignesh Chauhan On

The simplest solution is that you can return message in json in your post method. and display that message in span instead of validation summary.

For example

return Json(new object[] { false, "Invalid user name or password" }, 
                           JsonRequestBehavior.AllowGet);