我有这样的观点
@model IEnumerable<DuckingOctoBear.Models.PostViewModel>
<p>
@if (User.IsInRole("Administrator") || User.IsInRole("Editor"))
{
@Html.ActionLink("Create New", "Create")
}
</p>
<div class="">
@foreach (DuckingOctoBear.Models.PostViewModel item in Model)
{
<a href="/Posts/Details/@item.Post.Id" class="post-element">
<h4>@Html.DisplayFor(modelItem => item.Post.Title)</h4>
<h6>
Inserted by @item.User.UserName at @item.Post.Date.ToString("dd MMMM yyyy hh:ss")
</h6>
<article>
@Html.Raw(item.Post.Text)
</article>
<span>
@if (User.IsInRole("Administrator") || User.IsInRole("Editor"))
{
@Html.ActionLink("Edit", "Edit", new { id = item.Post.Id })
<span>|</span>
}
@Html.ActionLink("Details", "Details", new { id = item.Post.Id })
<span>|</span>
@if (User.IsInRole("Administrator"))
{
@Html.ActionLink("Delete", "Delete", new { id = item.Post.Id })
<span>|</span>
}
</span>
</a>
}
</div>
...我想要包含一个Javascript
文件,该文件与 _Layout.cshtml
Javascript
文件有很强的依赖关系
<div class="container body-content">
@RenderBody()
<hr />
<footer>
<p>© @DateTime.Now.Year - My ASP.NET Application</p>
</footer>
</div>
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
如何在不将其注册到捆绑包中的情况下包含该本地文件,对所有视图都是如此?
答案 0 :(得分:0)
好的史诗失败
这个_Layout.cshtml
<div class="container body-content">
@RenderBody()
<hr />
<footer>
<p>© @DateTime.Now.Year - My ASP.NET Application</p>
</footer>
</div>
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)
我只能添加一个新的部分
@RenderSection("LocallyScriptLibrary", required: false)
然后在目标视图中执行:
@section LocalScriptLibrary{
<script src="~/Scripts/LocalLibrary.js"></script>
}