3

I have a form in razor page with 2 button.

 <form method="post" class="form-group ">
<div class="form-group col-md-3">
  <div class="input-group">
    <input asp-for="DoctorViewModel.NationalCode" class="form-control" type="text" maxlength="10" required onblur="">
    <div class="input-group-append">
         <button class="btn btn-outline-primary " asp-page-handler="GetInfo" >search</button>
      </div>
   </div>
   <span asp-validation-for="DoctorViewModel.NationalCode"></span>
 </div>

 .
 .
 <div class="form-group col-md-2">
      <label asp-for="DoctorViewModel.Name" class="col-form-label"></label>
      <input asp-for="DoctorViewModel.Name" class="form-control" type="text" maxlength="50" required>
      <span asp-validation-for="DoctorViewModel.Name"></span>
 </div>
 .
 .
 .
 .
 <input type="submit" class="btn btn-success" value="Save"/>
 </form>

and when click on search button i wants to load form info from a handler.

but when click this button get validation error. How i can disable validation check for only search button. in asp.net form i used CauseValidation=false.

2 Answers 2

11

To skip validation while still using a submit-button, you can try to add the attribute formnovalidate :

<button class="btn btn-outline-primary" formnovalidate asp-page-handler="GetInfo">search</button>
Sign up to request clarification or add additional context in comments.

Comments

-1

The default type for a button is to submit the form it is contained within in most browsers.

You simply need to add a type of button and this should stop the submit and therefore the automatic validation will not trigger.

<button class="btn btn-outline-primary " type="button" asp-page-handler="GetInfo" >search</button>

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.