1

Im using asp.net mvc with jqueryui

I have placed the default logon htlm (that comes with a new created mvc project) and placed it in a jquery modal dialog. login seems to work okay. However Im not sure how I'm meant to handle errors. I'd like it to just show up in the modal dialog...,

The modal dialog is fine when it errors if for example a required field is missing, (it shows up in the dialog)

but the LogOn action method returns View(model); if there are any errors with the authenticating the credential entered( user/password are invalid)

how can i make it so that these erros get rendered within the dialog too?

raklos
  • 28,027
  • 60
  • 183
  • 301

2 Answers2

0

Add the errors to your Model and then read those values out in the view.

  public class LoginModel
  {
      public string ErrorMessage { get; set; }
  }
John Farrell
  • 24,673
  • 10
  • 77
  • 110
0

I suggest you check my blog post where I provide the best possible solution to handling validation errors using Ajax calls.

To make things reusable and to not repeat code the solution provides an action filter that handles certain exceptions. In this case a custom exception.

Everything is described and explained in great detail and all code is provided. It's actually very trivial when you look at it at the end but nevertheless. Check it out.

Robert Koritnik
  • 103,639
  • 52
  • 277
  • 404