Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Client Side validation for one submit button in ASP.NET MVC4

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

like image 757
vellaichamy Avatar asked Jul 02 '14 10:07

vellaichamy


People also ask

How do you disable client-side validation?

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.

How do you remove data annotation validation on client-side?

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.

How client-side validation is enabled on a JSP form?

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.


2 Answers

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.

like image 91
Ashwini Verma Avatar answered Oct 31 '22 08:10

Ashwini Verma


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

like image 31
ASalameh Avatar answered Oct 31 '22 08:10

ASalameh