问题描述
我有一个使用_Layout.cshtml的视图,并且将视图告诉参考脚本库,这是多余的,因为您将从_Layout.cshtml引用脚本库,或者我在这里遗漏了一些东西.在我从Microsoft获得的所有MVC教程中,它们始终使参考脚本库"处于选中状态.
I you have a view that is using the _Layout.cshtml and you tell the view to Reference script libraries, is that redundant since you will be referencing the script libraries from the _Layout.cshtml or am I missing something here. In all of the MVC tutorials I have gone through from Microsoft, they always leave Reference Script Libraries checked.
推荐答案
当您选中参考脚本库"时,这只会添加对jquery.validate.min.js
和jquery.validate.unobtrusive.min.js
的引用,您只需要在具有表单的页面上使用这些javascript库即可.验证用户输入的内容.
When you check "Reference Script Libraries" this just adds references to jquery.validate.min.js
and jquery.validate.unobtrusive.min.js
you would only need these javascript libraries on pages with forms as it validates what a user has entered.
您通常不会在_Layout.cshtml
中引用这些内容,因为在非格式页面上不需要它们,并且在加载页面时会执行不必要的HTTP请求.
You generally wouldn't reference these in the _Layout.cshtml
as they are not needed on non-form pages and would be unnecessary HTTP request performed when loading the page.
但是,如果您确实在每个页面或大多数页面上都有一个表单,并且认为可以在没有表单的页面上进行HTTP请求,则可以在_Layout.cshtml
中引用它们,而不必检查参考脚本库"创建视图时.
If however you do have a form on every page or most pages and think it is acceptable to make the HTTP request on pages without forms then you can reference them in the _Layout.cshtml
and simply not check the "Reference Script Libraries" when creating views.
这篇关于在视图中引用脚本库并使用_Layout.cshtml冗余吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!