The client side validation in ASP.Net Core (Unlike ASP.Net MVC 5) is not working. I have the following code:
public class CountryModel{
[Required]
public String Title {get; set;}
}
and in my view page
using(Html.BeginForm()){
@Html.LabelFor(x=> x.Title)
@Html.ValidationMessageFor(x=> x.Title)
@Html.EditorFor(x=> x.Title)
<Button>Add</Button>
}
with the following scripts added to the end of the page:
...
<script src="~/lib/jquery/dist/jquery.js"></script>
<script src="~/lib/jquery-validation/dist/jquery.validate.min.js"></script>
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script>
But it fails. I have check the script through viewing the source in my browser and the scripts have been loaded properly. I have pointed a break point to my Action API to double check, and any time the add button is pressed I reach the break point meaning the client side validation fails.
Is there any additional configuration in ASP.Net Core?? Because this approach works just fine in MVC 5.




Please make sure your validation-related scripts are placed under the environment which you are using. Development Or Production.
I was struggling for some time and when I checked my script it was placed in the development section and my app was running using the production environment.
Once I placed the scripts under production it started working !