0

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!

adiga
  • 34,372
  • 9
  • 61
  • 83
TiagoM
  • 3,458
  • 4
  • 42
  • 83
  • so do you want to show either error msg 1 or 2? – Amr Elgarhy Oct 16 '17 at 11:02
  • or show both but not as bullet points? – Amr Elgarhy Oct 16 '17 at 11:02
  • Seems that your best option is a separate validation message. Something like "if whole thing not valid show this message". Or refer to this answer: https://stackoverflow.com/q/918969/728795 – Andrei Oct 16 '17 at 11:03
  • @AmrElgarhy I want to show error msg 1 or error msg 2, not both! And I dont want to add them on ModelState because that will use bullet points – TiagoM Oct 16 '17 at 12:16

1 Answers1

0

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);
Kazimierz Jawor
  • 18,861
  • 7
  • 35
  • 55
  • That's too much for showing a error message, I would want to maintain the signature of my method, but thanks – TiagoM Oct 16 '17 at 12:17