Reputation: 143
I have created the view in MVC 4.0 and i have placed four text boxes and two submit buttons, one for create and one for cancel. Validation should be occur for the text boxes while i am clicking the create button. while clicking the cancel button, we need disable the validation. in ASP.NET, we can achieve this by setting the CausesValidation = false for the cancel button. in MVC 4.0, how we will achieve this? Could you please help me on this.
Thanks
Upvotes: 6
Views: 8882
Reputation: 7525
Just add class="cancel"
to the button
For example,
<input type="submit" name="btnCancel" value="Cancel" class="cancel"/>
Updated
Use this link to identify which submit button has been pressed.
Upvotes: 9
Reputation: 803
you don't have to make a cancel button submit instead you can make it link button
@Html.ActionLink("Back","ActionName")
or you can make it <input type="button" value="Cancel" onclick="JsFunction()" />
the two cases they will not affect with validation
Upvotes: 4