Asp.net mvc 4 asp.net mvc4:在捆绑包上动态添加参数
我想为mvc应用程序添加皮肤支持,允许添加多个皮肤,并让用户选择首选皮肤 皮肤目录将在cookie中从数据库接收 为了实现这一点,我想创建一个参数化的bundle,它将为皮肤指定的目录作为输入,并为指定的路径动态创建bundleAsp.net mvc 4 asp.net mvc4:在捆绑包上动态添加参数,asp.net-mvc-4,skin,bundles,Asp.net Mvc 4,Skin,Bundles,我想为mvc应用程序添加皮肤支持,允许添加多个皮肤,并让用户选择首选皮肤 皮肤目录将在cookie中从数据库接收 为了实现这一点,我想创建一个参数化的bundle,它将为皮肤指定的目录作为输入,并为指定的路径动态创建bundle bundles.Add(new StyleBundle("~/Content/css") .Include( "~/Content/{skinDirectory}/reset.css", "~/Co
bundles.Add(new StyleBundle("~/Content/css")
.Include(
"~/Content/{skinDirectory}/reset.css",
"~/Content/{skinDirectory}/site.css",
"~/Content/{skinDirectory}/grids.css")
);
其中{0}是我从bundle发送的目录名,我在我的_布局页面中这样调用它:
@Styles.Render("~/Content/css", skinDirectory)
这可能吗?这可能有点晚,但可能会帮助其他人。是的,这是可能的
public static class DynamicBundles
{
public static IHtmlString RenderSkin(string skinDirectory)
{
BundleTable.Bundles.Add(new StyleBundle("~/Content/css/" + skinDirectory).Include(
"~/Content/" + skinDirectory + "/reset.css",
"~/Content/" + skinDirectory + "/site.css",
"~/Content/" + skinDirectory + "/grids.css"));
return Styles.Render("~/Content/css/" + skinDirectory);
}
}
然后在您的_布局页面中使用
@DynamicBundles.RenderSkin(skinDirectory)