2

I want to be able to provide a message on my screen that says 'The user name or password provided is incorrect'. So I have the following statement in my controller:

ModelState.AddModelError("", "The user name or password provided is incorrect.");

And then on my view I have

@Html.ValidationSummary(true, "Login was unsuccessful.")

But that gives me the message:

Login was unsuccessful

  • The user name or password provided is incorrect

So how do I just display one of these messages rather than both?

Exitos
  • 29,230
  • 38
  • 123
  • 178

1 Answers1

1

If you want to get rid of the first text why not just use the other overload of the ValidationSummary method?

@Html.ValidationSummary(true)
Andreas
  • 1,355
  • 9
  • 15
  • this is okay but I still get an annoying bullet point on it, any idea how to just display the message? – Exitos Nov 06 '11 at 19:38
  • I think the easiest is to just use css to remove the bullet style. Otherwise you could loop through the model state errors manually in your view. See the following question: http://stackoverflow.com/questions/573302/how-do-i-get-the-collection-of-model-state-errors-in-asp-net-mvc – Andreas Nov 06 '11 at 21:08