[ACCEPTED]-Populate a Razor Section From a Partial-razor
The way I dealt with this is to write a 13 couple extension methods to the HtmlHelper 12 class. That allows partials views to say 11 that they require a script, and then in 10 the layout view that writes the tag I call 9 to my helper method to emit the required 8 scripts
Here are the helper methods:
public static string RequireScript(this HtmlHelper html, string path, int priority = 1)
{
var requiredScripts = HttpContext.Current.Items["RequiredScripts"] as List<ResourceInclude>;
if (requiredScripts == null) HttpContext.Current.Items["RequiredScripts"] = requiredScripts = new List<ResourceInclude>();
if (!requiredScripts.Any(i => i.Path == path)) requiredScripts.Add(new ResourceInclude() { Path = path, Priority = priority });
return null;
}
public static HtmlString EmitRequiredScripts(this HtmlHelper html)
{
var requiredScripts = HttpContext.Current.Items["RequiredScripts"] as List<ResourceInclude>;
if (requiredScripts == null) return null;
StringBuilder sb = new StringBuilder();
foreach (var item in requiredScripts.OrderByDescending(i => i.Priority))
{
sb.AppendFormat("<script src=\"{0}\" type=\"text/javascript\"></script>\n", item.Path);
}
return new HtmlString(sb.ToString());
}
public class ResourceInclude
{
public string Path { get; set; }
public int Priority { get; set; }
}
Once 7 you have that in place your partial view 6 just needs to call @Html.RequireScript("/Path/To/Script")
.
And in the layout view's 5 head section you call @Html.EmitRequiredScripts()
.
An added bonus of 4 this is that it allows you to weed out duplicate 3 script requests. If you have multiple views/partial 2 views that need a given script you can safely 1 assume that you will only output it once
Partial views cannot participate in their 1 parent views' sections.
You could have a second partial that is 6 only in charge of injecting the necessary 5 javascript. Place several scripts in there 4 around @if
blocks, if you want:
@model string
@if(Model == "bla") {
<script type="text/javascript">...</script>
}
@else if(Model == "bli") {
<script type="text/javascript">...</script>
}
This could obviously 3 be cleaned up a bit, but then, in the Scripts
section 2 of your view:
@section Scripts
{
@Html.Partial("_Scripts", "ScriptName_For_Partial1")
}
Again, it might not win a beauty 1 prize but it will work.
The more elegant way to do this is to move 4 partial view scripts into separate file 3 and then render it in Scripts section of 2 view:
<h2>This is the view</h2>
@Html.RenderPartial("_Partial")
@section Scripts
{
@Html.RenderPartial("_PartialScripts")
<script type="text/javascript">
alert("I'm a view script.");
</script>
}
The partial view _Partial.cshtml:
<p>This is the partial.</p>
The partial view 1 _PartialScripts.cshtml with scripts only:
<script type="text/javascript">
alert("I'm a partial script!");
</script>
Install the Forloop.HtmlHelpers nuget package - it adds some 17 helpers for managing scripts in partial 16 views and editor templates.
Somewhere in 15 your layout, you need to call
@Html.RenderScripts()
This will 14 be where any script files and script blocks 13 will be outputted in the page so I would 12 recommend putting it after your main scripts 11 in the layout and after a scripts section 10 (if you have one).
If you're using The Web 9 Optimization Framework with bundling, you 8 can use the overload
@Html.RenderScripts(Scripts.Render)
so that this method 7 is used for writing out script files.
Now, anytime 6 you want to add script files or blocks in 5 a view, partial view or template, simply 4 use
@using (Html.BeginScriptContext())
{
Html.AddScriptFile("~/Scripts/jquery.validate.js");
Html.AddScriptBlock(
@<script type="text/javascript">
$(function() { $('#someField').datepicker(); });
</script>
);
}
The helpers ensure that only one script 3 file reference is rendered if added multiple 2 times and it also ensures that script files 1 are rendered out in an expected order i.e.
- Layout
- Partials and Templates (in the order in which they appear in the view, top to bottom)
[Updated version] Updated version following @Necrocubus 9 question to Include inline scripts.
public static class ScriptsExtensions
{
const string REQ_SCRIPT = "RequiredScript";
const string REQ_INLINESCRIPT = "RequiredInlineScript";
const string REQ_STYLE = "RequiredStyle";
#region Scripts
/// <summary>
/// Adds a script
/// </summary>
/// <param name="html"></param>
/// <param name="path"></param>
/// <param name="priority">Ordered by decreasing priority </param>
/// <param name="bottom"></param>
/// <param name="options"></param>
/// <returns></returns>
public static string RequireScript(this IHtmlHelper html, string path, int priority = 1, bool bottom=false, params string[] options)
{
var ctxt = html.ViewContext.HttpContext;
var requiredScripts = ctxt.Items[REQ_SCRIPT] as List<ResourceToInclude>;
if (requiredScripts == null) ctxt.Items[REQ_SCRIPT] = requiredScripts = new List<ResourceToInclude>();
if (!requiredScripts.Any(i => i.Path == path)) requiredScripts.Add(new ResourceToInclude() { Path = path, Priority = priority, Options = options, Type=ResourceType.Script, Bottom=bottom});
return null;
}
/// <summary>
///
/// </summary>
/// <param name="html"></param>
/// <param name="script"></param>
/// <param name="priority">Ordered by decreasing priority </param>
/// <param name="bottom"></param>
/// <returns></returns>
public static string RequireInlineScript(this IHtmlHelper html, string script, int priority = 1, bool bottom = false)
{
var ctxt = html.ViewContext.HttpContext;
var requiredScripts = ctxt.Items[REQ_INLINESCRIPT] as List<InlineResource>;
if (requiredScripts == null) ctxt.Items[REQ_INLINESCRIPT] = requiredScripts = new List<InlineResource>();
requiredScripts.Add(new InlineResource() { Content=script, Priority = priority, Bottom=bottom, Type=ResourceType.Script});
return null;
}
/// <summary>
/// Just call @Html.EmitRequiredScripts(false)
/// at the end of your head tag and
/// @Html.EmitRequiredScripts(true) at the end of the body if some scripts are set to be at the bottom.
/// </summary>
public static HtmlString EmitRequiredScripts(this IHtmlHelper html, bool bottom)
{
var ctxt = html.ViewContext.HttpContext;
var requiredScripts = ctxt.Items[REQ_SCRIPT] as List<ResourceToInclude>;
var requiredInlineScripts = ctxt.Items[REQ_INLINESCRIPT] as List<InlineResource>;
var scripts = new List<Resource>();
scripts.AddRange(requiredScripts ?? new List<ResourceToInclude>());
scripts.AddRange(requiredInlineScripts ?? new List<InlineResource>());
if (scripts.Count==0) return null;
StringBuilder sb = new StringBuilder();
foreach (var item in scripts.Where(s=>s.Bottom==bottom).OrderByDescending(i => i.Priority))
{
sb.Append(item.ToString());
}
return new HtmlString(sb.ToString());
}
#endregion Scripts
#region Styles
/// <summary>
///
/// </summary>
/// <param name="html"></param>
/// <param name="path"></param>
/// <param name="priority">Ordered by decreasing priority </param>
/// <param name="options"></param>
/// <returns></returns>
public static string RequireStyle(this IHtmlHelper html, string path, int priority = 1, params string[] options)
{
var ctxt = html.ViewContext.HttpContext;
var requiredScripts = ctxt.Items[REQ_STYLE] as List<ResourceToInclude>;
if (requiredScripts == null) ctxt.Items[REQ_STYLE] = requiredScripts = new List<ResourceToInclude>();
if (!requiredScripts.Any(i => i.Path == path)) requiredScripts.Add(new ResourceToInclude() { Path = path, Priority = priority, Options = options });
return null;
}
/// <summary>
/// Just call @Html.EmitRequiredStyles()
/// at the end of your head tag
/// </summary>
public static HtmlString EmitRequiredStyles(this IHtmlHelper html)
{
var ctxt = html.ViewContext.HttpContext;
var requiredScripts = ctxt.Items[REQ_STYLE] as List<ResourceToInclude>;
if (requiredScripts == null) return null;
StringBuilder sb = new StringBuilder();
foreach (var item in requiredScripts.OrderByDescending(i => i.Priority))
{
sb.Append(item.ToString());
}
return new HtmlString(sb.ToString());
}
#endregion Styles
#region Models
public class InlineResource : Resource
{
public string Content { get; set; }
public override string ToString()
{
return "<script>"+Content+"</script>";
}
}
public class ResourceToInclude : Resource
{
public string Path { get; set; }
public string[] Options { get; set; }
public override string ToString()
{
switch(Type)
{
case ResourceType.CSS:
if (Options == null || Options.Length == 0)
return String.Format("<link rel=\"stylesheet\" href=\"{0}\" type=\"text/css\" />\n", Path);
else
return String.Format("<link rel=\"stylesheet\" href=\"{0}\" type=\"text/css\" {1} />\n", Path, String.Join(" ", Options));
default:
case ResourceType.Script:
if (Options == null || Options.Length == 0)
return String.Format("<script src=\"{0}\" type=\"text/javascript\"></script>\n", Path);
else
return String.Format("<script src=\"{0}\" type=\"text/javascript\" {1}></script>\n", Path, String.Join(" ", Options));
}
}
}
public class Resource
{
public ResourceType Type { get; set; }
public int Priority { get; set; }
public bool Bottom { get; set; }
}
public enum ResourceType
{
Script,
CSS
}
#endregion Models
}
My 2 8 cents, it is an old post, but still relevant, so 7 here is an upgraded update of Mr Bell's 6 solution which works with ASP.Net Core.
It 5 allows adding scripts and styles to the 4 main layout from imported partial views 3 and subviews, and possibility to add options 2 to script/style imports (like async defer 1 etc):
public static class ScriptsExtensions
{
const string REQ_SCRIPT = "RequiredScript";
const string REQ_STYLE = "RequiredStyle";
public static string RequireScript(this IHtmlHelper html, string path, int priority = 1, params string[] options)
{
var ctxt = html.ViewContext.HttpContext;
var requiredScripts = ctxt.Items[REQ_SCRIPT] as List<ResourceInclude>;
if (requiredScripts == null) ctxt.Items[REQ_SCRIPT] = requiredScripts = new List<ResourceInclude>();
if (!requiredScripts.Any(i => i.Path == path)) requiredScripts.Add(new ResourceInclude() { Path = path, Priority = priority, Options = options });
return null;
}
public static HtmlString EmitRequiredScripts(this IHtmlHelper html)
{
var ctxt = html.ViewContext.HttpContext;
var requiredScripts = ctxt.Items[REQ_SCRIPT] as List<ResourceInclude>;
if (requiredScripts == null) return null;
StringBuilder sb = new StringBuilder();
foreach (var item in requiredScripts.OrderByDescending(i => i.Priority))
{
if (item.Options == null || item.Options.Length == 0)
sb.AppendFormat("<script src=\"{0}\" type=\"text/javascript\"></script>\n", item.Path);
else
sb.AppendFormat("<script src=\"{0}\" type=\"text/javascript\" {1}></script>\n", item.Path, String.Join(" ", item.Options));
}
return new HtmlString(sb.ToString());
}
public static string RequireStyle(this IHtmlHelper html, string path, int priority = 1, params string[] options)
{
var ctxt = html.ViewContext.HttpContext;
var requiredScripts = ctxt.Items[REQ_STYLE] as List<ResourceInclude>;
if (requiredScripts == null) ctxt.Items[REQ_STYLE] = requiredScripts = new List<ResourceInclude>();
if (!requiredScripts.Any(i => i.Path == path)) requiredScripts.Add(new ResourceInclude() { Path = path, Priority = priority, Options = options });
return null;
}
public static HtmlString EmitRequiredStyles(this IHtmlHelper html)
{
var ctxt = html.ViewContext.HttpContext;
var requiredScripts = ctxt.Items[REQ_STYLE] as List<ResourceInclude>;
if (requiredScripts == null) return null;
StringBuilder sb = new StringBuilder();
foreach (var item in requiredScripts.OrderByDescending(i => i.Priority))
{
if (item.Options == null || item.Options.Length == 0)
sb.AppendFormat("<link rel=\"stylesheet\" href=\"{0}\" type=\"text/css\" />\n", item.Path);
else
sb.AppendFormat("<link rel=\"stylesheet\" href=\"{0}\" type=\"text/css\" {1} />\n", item.Path, String.Join(" ", item.Options));
}
return new HtmlString(sb.ToString());
}
public class ResourceInclude
{
public string Path { get; set; }
public int Priority { get; set; }
public string[] Options { get; set; }
}
}
For those looking for the aspnet core 2.0 3 version:
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Http;
public static class HttpContextAccessorExtensions
{
public static string RequireScript(this IHttpContextAccessor htmlContextAccessor, string path, int priority = 1)
{
var requiredScripts = htmlContextAccessor.HttpContext.Items["RequiredScripts"] as List<ResourceInclude>;
if (requiredScripts == null) htmlContextAccessor.HttpContext.Items["RequiredScripts"] = requiredScripts = new List<ResourceInclude>();
if (requiredScripts.All(i => i.Path != path)) requiredScripts.Add(new ResourceInclude() { Path = path, Priority = priority });
return null;
}
public static HtmlString EmitRequiredScripts(this IHttpContextAccessor htmlContextAccessor)
{
var requiredScripts = htmlContextAccessor.HttpContext.Items["RequiredScripts"] as List<ResourceInclude>;
if (requiredScripts == null) return null;
StringBuilder sb = new StringBuilder();
foreach (var item in requiredScripts.OrderByDescending(i => i.Priority))
{
sb.AppendFormat("<script src=\"{0}\" type=\"text/javascript\"></script>\n", item.Path);
}
return new HtmlString(sb.ToString());
}
public class ResourceInclude
{
public string Path { get; set; }
public int Priority { get; set; }
}
}
Add to your layout after the scripts 2 render section call:
@HttpContextAccessor.EmitRequiredScripts()
And in your partial 1 view:
@inject IHttpContextAccessor HttpContextAccessor
...
@HttpContextAccessor.RequireScript("/scripts/moment.min.js")
You can create a new Layout
page and wrap the 19 PartialView inside of a Full View that is 18 responsible for rendering the contents and 17 also any library sections.
For example, let's 16 say I have the following code:
HomeController.cs
[HttpGet]
public ActionResult About()
{
var vm = new AboutViewModel();
return View("About", vm);
}
When the Full 15 Page view is rendered, it's typically renderedby 14 merging two files:
About.cshtml
@model AboutViewModel
@{
ViewBag.Title = "About CSHN";
}
<h3>@ViewBag.Title</h3>
@section Styles {
<style> /* style info here */ </style>
}
@section Scripts {
<script> /* script info here */ </script>
}
_Layout.cshtml
(or whatever is specified in _ViewStart or overridden in the page)
<!DOCTYPE html>
<html>
<head>
@RenderSection("Styles", false)
<title>@ViewBag.Title</title>
</head>
<body>
@RenderBody()
@RenderSection("scripts", false)
</body>
</html>
Now, suppose you wanted 13 to Render About.cshtml
as a Partial View, perhaps as modal window 12 in response to AJAX call. The goal here 11 being to return only the content specified 10 in the about page, scripts and all, without 9 all the bloat included in the _Layout.cshtml
master layout 8 (like a full <html>
document).
You might try it 7 like this, but it won't come with any of 6 the section blocks:
return PartialView("About", vm);
Instead, add a simpler 5 layout page like this:
_PartialLayout.cshtml
<div>
@RenderBody()
@RenderSection("Styles", false)
@RenderSection("scripts", false)
</div>
Or to support a modal 4 window like this:
_ModalLayout.cshtml
<div class="modal modal-page fade" tabindex="-1" role="dialog" >
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">@ViewBag.Title</h4>
</div>
<div class="modal-body">
@RenderBody()
@RenderSection("Styles", false)
@RenderSection("scripts", false)
</div>
<div class="modal-footer">
<button type="button" class="btn btn-inverse" data-dismiss="modal">Dismiss</button>
</div>
</div>
</div>
</div>
Then you can specify a custom Master View in this 3 controller or any other handler that you 2 want to render the contents and scripts 1 of a view simultaneously
[HttpGet]
public ActionResult About()
{
var vm = new AboutViewModel();
return !Request.IsAjaxRequest()
? View("About", vm)
: View("About", "~/Views/Shared/_ModalLayout.cshtml", vm);
}
Base on the answer from Mr Bell And Shimmy 3 above, I add on extra function for Bundle 2 script.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Web.Mvc;
namespace ABC.Utility
{
public static class PartialViewHelper
{
public static string RequireScript(this HtmlHelper html, string path, int priority = 1)
{
var requiredScripts = HttpContext.Current.Items["RequiredScripts"] as List<ResourceInclude>;
if (requiredScripts == null) HttpContext.Current.Items["RequiredScripts"] = requiredScripts = new List<ResourceInclude>();
if (!requiredScripts.Any(i => i.Path == path)) requiredScripts.Add(new ResourceInclude() { Path = path, Priority = priority });
return null;
}
public static string RequireBundleStyles(this HtmlHelper html, string bundleName)
{
var a = System.Web.Optimization.Styles.Render(bundleName);
var requiredStyles = HttpContext.Current.Items["RequiredStyles"] as IHtmlString;
if (requiredStyles == null) HttpContext.Current.Items["RequiredStyles"] = requiredStyles = a;
return null;
}
public static string RequireBundleScripts(this HtmlHelper html, string bundleName)
{
var a=System.Web.Optimization.Scripts.Render(bundleName);
var requiredScripts = HttpContext.Current.Items["RequiredScripts"] as IHtmlString;
if (requiredScripts == null) HttpContext.Current.Items["RequiredScripts"] = requiredScripts = a;
return null;
}
public static HtmlString EmitRequiredBundleStyles(this HtmlHelper html)
{
var requiredStyles = HttpContext.Current.Items["RequiredStyles"] as IHtmlString;
if (requiredStyles == null) return null;
return MvcHtmlString.Create(requiredStyles.ToHtmlString()) ;
}
public static HtmlString EmitRequiredBundleScripts(this HtmlHelper html)
{
var requiredScripts = HttpContext.Current.Items["RequiredScripts"] as IHtmlString;
if (requiredScripts == null) return null;
return MvcHtmlString.Create(requiredScripts.ToHtmlString());
}
public static HtmlString EmitRequiredScripts(this HtmlHelper html)
{
var requiredScripts = HttpContext.Current.Items["RequiredScripts"] as List<ResourceInclude>;
if (requiredScripts == null) return null;
StringBuilder sb = new StringBuilder();
foreach (var item in requiredScripts.OrderByDescending(i => i.Priority))
{
sb.AppendFormat("<script src=\"{0}\" type=\"text/javascript\"></script>\n", item.Path);
}
return new HtmlString(sb.ToString());
}
public class ResourceInclude
{
public string Path { get; set; }
public int Priority { get; set; }
}
}//end class
}// end namespace
Sample on PartialView :- @Html.RequireBundleStyles("~/bundles/fileupload/bootstrap/BasicPlusUI/css"); @Html.RequireBundleScripts("~/bundles/fileupload/bootstrap/BasicPlusUI/js");
Sample 1 on MasterPage :- @Html.EmitRequiredBundleStyles()
Use @using(Html.Delayed()){ ...your content... }
extensions from answer https://stackoverflow.com/a/18790222/1037948 to render any 3 content (scripts or just HTML) later in 2 the page. Internal Queue
should ensure correct 1 ordering.
This functionality is also implemented in 3 ClientDependency.Core.Mvc.dll. It provides 2 the html helpers: @Html.RequiresJs and @Html.RenderJsHere(). Nuget 1 package: ClientDependency-Mvc
Here cames my solution to the frequently 32 asked questions "how to inject sections 31 from partial views to main views or main 30 layout view for asp.net mvc?". If you 29 do a search on stackoverflow by keywords 28 "section + partial", you will 27 get quite a big list of related questions, and 26 given answers, but none of them are seems 25 elegant to me by means of the razor engine 24 grammar. So I just take a look to the Razor 23 engine see if there could be a some better 22 solution to this question.
Fortunately, I 21 found something it is interesting to me 20 of how the Razor engine does the compilation 19 for the view template file (*.cshtml, *.vbhtml). (I 18 will explain later), below is my code of 17 the solution which I think is quite simple 16 and elegant enough in usage.
namespace System.Web.Mvc.Html
{
public static class HtmlHelperExtensions
{
/// <summary>
/// 确保所有视图,包括分部视图(PartialView)中的节(Section)定义被按照先后顺序追加到最终文档输出流中
/// </summary>
public static MvcHtmlString EnsureSection(this HtmlHelper helper)
{
var wp = (WebViewPage)helper.ViewDataContainer;
Dictionary<string, WebPages.SectionWriter> sw = (Dictionary<string, WebPages.SectionWriter>)typeof(WebPages.WebPageBase).GetProperty("SectionWriters", Reflection.BindingFlags.NonPublic | Reflection.BindingFlags.Instance).GetValue(wp);
if (!helper.ViewContext.HttpContext.Items.Contains("SectionWriter"))
{
Dictionary<string, Stack<WebPages.SectionWriter>> qss = new Dictionary<string, Stack<WebPages.SectionWriter>>();
helper.ViewContext.HttpContext.Items["SectionWriter"] = qss;
}
var eqs = (Dictionary<string, Stack<WebPages.SectionWriter>>)helper.ViewContext.HttpContext.Items["SectionWriter"];
foreach (var kp in sw)
{
if (!eqs.ContainsKey(kp.Key)) eqs[kp.Key] = new Stack<WebPages.SectionWriter>();
eqs[kp.Key].Push(kp.Value);
}
return MvcHtmlString.Create("");
}
/// <summary>
/// 在文档流中渲染指定的节(Section)
/// </summary>
public static MvcHtmlString RenderSectionEx(this HtmlHelper helper, string section, bool required = false)
{
if (helper.ViewContext.HttpContext.Items.Contains("SectionWriter"))
{
Dictionary<string, Stack<WebPages.SectionWriter>> qss = (Dictionary<string, Stack<WebPages.SectionWriter>>)helper.ViewContext.HttpContext.Items["SectionWriter"];
if (qss.ContainsKey(section))
{
var wp = (WebViewPage)helper.ViewDataContainer;
var qs = qss[section];
while (qs.Count > 0)
{
var sw = qs.Pop();
var os = ((WebViewPage)sw.Target).OutputStack;
if (os.Count == 0) os.Push(wp.Output);
sw.Invoke();
}
}
else if (!qss.ContainsKey(section) && required)
{
throw new Exception(string.Format("'{0}' section is not defined.", section));
}
}
return MvcHtmlString.Create("");
}
}
}
usage: To use the 15 code is quite simple as well, and it looks 14 almost the same style to the usual. It also 13 supports any levels to the nested partial 12 views. ie. I have a view template chain: _ViewStart.cshtml->layout.cshtml->index.cshtml->[head.cshtml,foot.cshtml]->ad.cshtml.
In 11 layout.cshtml, we have:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>@ViewBag.Title - @ViewBag.WebSetting.Site.WebName</title>
<base href="@ViewBag.Template/" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta http-equiv="Cache-Control" content="no-siteapp" />
<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1.0, user-scalable=0,user-scalable=no">
<meta name="format-detection" content="telephone=no">
<meta name="renderer" content="webkit">
<meta name="author" content="Taro Technology Co.,LTD" />
<meta name="robots" content="index,follow" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<link rel="alternate icon" type="@ViewBag.WebSetting.Site.WebFavIcon" href="@ViewBag.WebSetting.Site.WebFavIcon">
@Html.RenderSectionEx("Head")
</head>
<body>
@RenderBody()
@Html.RenderSectionEx("Foot")
</body>
</html>
And in index.cshtml, we 10 have:
@{
ViewBag.Title = "首页";
}
@Html.Partial("head")
<div class="am-container-1">
.......
</div>
@Html.Partial("foot")
And in head.cshtml, we would have the 9 code:
@section Head{
<link rel="stylesheet" href="assets/css/amazeui.css" />
<link rel="stylesheet" href="assets/css/style.css" />
}
<header class="header">
......
</header>
@Html.EnsureSection()
it is the same in foot.cshtml or ad.cshtml, you 8 can still define Head or Foot section in 7 them, make sure to call @Html.EnsureSection() once 6 at the end of the partial view file. That's 5 all you need to do to get rid of the subjected 4 issue in asp mvc.
I just share my code snippet 3 so others may take use of it. If you feel 2 it is useful, please don't hesitate to up 1 rate my post. :)
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.