Alex Rivera | Logout

Clear ASP.Net MVC validation messages with jQuery

Asked 2011-01-24T22:52:09.523
10

In my asp.net mvc page I need to have a "clear" button that resets certain input fields and clears all the error messages. Clearing the inputs is fine but because the validation messages are generated by the asp.net mvc javascript it's not obvious to me how to clear them?

Update: This ended up working well for me.

$(".field-validation-error").empty();
Edit
Report

1 Answer

5

You can view the html code generated in the browser and then just empty it through jquery e.g. empty()

To find the generated code:

  • Normal postback: view the page's "source code" in the browser and look for the error message. Find the parent div to empty it.
  • Ajax call: right click and inspect elements in Chrome (other modern browsers call it differently but they should have the tool). This will give you the html generated at the current state (after the ajax call). Find the parent div and empty it.

Hope this helps

answered 2011-01-24T23:08:47.910

Your Answer