我有以下捆绑
bundles.Add(new ScriptBundle("~/bundles/2013").Include(
"~/Scripts/2013/app.js",
"~/Scripts/2013/controllers/*.js",
"~/Scripts/2013/directives.js"));
bundles.Add(new ScriptBundle("~/bundles/2014").Include(
"~/Scripts/2014/app.js",
"~/Scripts/2014/controllers/*.js",
"~/Scripts/2014/directives.js"));
如何将年份设置为变量以获得它
bundles.Add(new ScriptBundle("~/bundles/{year}").Include(
"~/Scripts/{year}/app.js",
"~/Scripts/{year}/controllers/*.js",
"~/Scripts/{year}/directives.js"));
并在前端
@Scripts.Render("~/bundles/@currentyear")
答案 0 :(得分:1)
不是更简单的创建做这样的事情:
var string year=now.Year;
bundles.Add(new ScriptBundle("~/bundles/"+ year).Include(
"~/Scripts/"+year+"/app.js",
"~/Scripts/"+year+"/controllers/*.js",
"~/Scripts/"+year+"/directives.js"));
Session.Add("bundleyear",year);
然后在页面
@Scripts.Render("~/bundles/" +<%=Session("bundleyear").tostring())