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
To disable client-side validation, set the page's ClientTarget property to 'Downlevel' ('Uplevel' forces client-side validation). Alternatively, you can set an individual validator control's EnableClientScript property to 'false' to disable client-side validation for that specific control.
We can enable and disable the client-side validation by setting the values of ClientValidationEnabled & UnobtrusiveJavaScriptEnabled keys true or false. This setting will be applied to application level. For client-side validation, the values of above both the keys must be true.
To enable client-side validation you have to place the Struts HTML Tag Library's javascript tag in each jsp page for which you need to preform client-side validation. The formName property of the javascript tag hold the name of the form specified in the validation. xml file.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With