Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable client side form validation in ASP.NET Core

How can I disable client-side form validation in my ASP.NET Core 1.1 app? But I need the server-side one.

like image 503
alvipeo Avatar asked Jul 07 '17 15:07

alvipeo


People also ask

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.

What is ModelState in asp net core?

Model state represents errors that come from two subsystems: model binding and model validation. Errors that originate from model binding are generally data conversion errors. For example, an "x" is entered in an integer field.

How can use client-side validation in asp net core?

The ASP.NET core includes unobtrusive client-side validation libraries, which makes it easier to add client side validation code, without writing a single line of code. In the previous tutorial on server side validation, we looked at how data annotations attributes are used by the Model Validator to validate the Model.


2 Answers

You do this in your ConfigureServices class in your Startup file:

services.AddMvc().AddViewOptions(options => 
    options.HtmlHelperOptions.ClientValidationEnabled = false);

This will work for the attributes generated by tag helpers.

like image 176
MaxT Avatar answered Oct 03 '22 03:10

MaxT


you just remove the javascript for jquery.unobtrusive.validation.js

In the VS project templates that is in _ValidationScriptsPartial.cshtml

like image 23
Joe Audette Avatar answered Oct 03 '22 05:10

Joe Audette