在默认的_Layout.cshtml文件中,脚本在环境"中定义,如下所示:
In the default _Layout.cshtml file, scripts are defined in "environment"s like so:
<environment names="Development"> <script src="~/lib/jquery/dist/jquery.js"></script> <script src="~/lib/bootstrap/dist/js/bootstrap.js"></script> <script src="~/js/site.js" asp-append-version="true"></script> </environment> <environment names="Staging,Production"> <script src="ajax.aspnetcdn/ajax/jquery/jquery-2.1.4.min.js" asp-fallback-src="~/lib/jquery/dist/jquery.min.js" asp-fallback-test="window.jQuery"> </script> <script src="ajax.aspnetcdn/ajax/bootstrap/3.3.5/bootstrap.min.js" asp-fallback-src="~/lib/bootstrap/dist/js/bootstrap.min.js" asp-fallback-test="window.jQuery && window.jQuery.fn && window.jQuery.fn.modal"> </script> <script src="~/js/site.min.js" asp-append-version="true"></script> </environment>下面是@RenderSection("scripts", required: false)
我似乎无法在任何单独的.cshtml文件中实现一个部分(在本例中为脚本"),因为看起来它们已在Core中摆脱了"@section"
I can't seem to implement a section (in this case "scripts") in any separate .cshtml file since it looks like they got rid of "@section" in Core
我想为特定视图添加特定脚本.解决这个问题的新方法是什么?我现在是否将所有内容都转储到_Layout中?
I would like to add specific scripts for specific views. What is the new way to go about this? Do I just dump everything in _Layout now?
推荐答案我认为您错了.它在ASP.NET Core中工作正常.我的_layout.cshtml
I think you are mistaken. It works just fine in ASP.NET Core. I have this in my _layout.cshtml
@RenderSection("scripts", required: false)在我的一种观点中,我正在像这样添加脚本:
and in one of my views I'm adding scripts there like this:
@section Scripts { @if (Model.CanEdit) { await Html.RenderPartialAsync("EditorScriptsPartial"); } }更多推荐
等同于"@section"在ASP.NET Core MVC中?
发布评论