Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Base on the answer from Mr Bell And Shimmy above, I add on extra function for Bundle script.</p> <pre><code>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&lt;ResourceInclude&gt;; if (requiredScripts == null) HttpContext.Current.Items["RequiredScripts"] = requiredScripts = new List&lt;ResourceInclude&gt;(); if (!requiredScripts.Any(i =&gt; 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&lt;ResourceInclude&gt;; if (requiredScripts == null) return null; StringBuilder sb = new StringBuilder(); foreach (var item in requiredScripts.OrderByDescending(i =&gt; i.Priority)) { sb.AppendFormat("&lt;script src=\"{0}\" type=\"text/javascript\"&gt;&lt;/script&gt;\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 </code></pre> <p>Sample on PartialView :- @Html.RequireBundleStyles("~/bundles/fileupload/bootstrap/BasicPlusUI/css"); @Html.RequireBundleScripts("~/bundles/fileupload/bootstrap/BasicPlusUI/js"); </p> <p>Sample on MasterPage :- @Html.EmitRequiredBundleStyles()</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload