Where to include the unobtrusive validation script
I'm pretty new in ASP.MVC and I feel that i'm missing something.
I'm using jquery unobstrusive validation, so in all my edit view, I include this
<script src="@Url.Content("~/Scripts/jquery.valid开发者_Go百科ate.min.js")" type="text/javascript" />
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript" />
Then, I thought that it will be fine to move this code from every edit view to the _layout file.
I did it, and now the all validations don't works.
The question is... why? I thought that if I include the script in the _layout file this will be included in all the views of my app. In fact, I'm including there an expander plugin and it's working propertly across the solution. Has the validation some special behaviour and I must include it in every edit view... or I'm doing something wrong?
Thanks.
Make sure that EVERY page that needs validation, does include this code on it:
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
as a recommendation, do include them manually, because by putting them inside _Layout, you are forcing every page to include a useless files on it, and this is not good for the overall experience of your site.
精彩评论