1

I am resetting the form using the below code.

$("#Create").trigger("reset");

This is clearing all the values except the validation error message.

I am showing validation error message as below.

  @if (ViewData.ModelState.Keys.Any(k => ViewData.ModelState[k].Errors.Any()))
   {
     <div class="alert alert-danger">
        <button class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
         @Html.ValidationSummary(false, "Errors: ")
     </div>
    }

How can I clear this ?

2 Answers 2

1

You could just remove those elements

$('.alert').remove()
Sign up to request clarification or add additional context in comments.

Comments

1

Because when you do reset it clears input fields but you have div filed where errors are generated so you need to clean that.

you can try

$("form").data('validator').resetForm();

or just

  $('.validation-summary-valid').removeClass('validation-summary-errors');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.