如何在ASP.NET MVC中包含Spark布局文件中的捆绑?

时间:2015-03-17 10:43:03

标签: asp.net-mvc spark-view-engine

我已经定义了捆绑包,我尝试使用以下语法在我的spark布局中使用它们。

${Scripts.Render("~/bundles/jqueryPlugins")}
${Scripts.Render("~/bundles/jqGridJqueryPlugins")}
${Scripts.Render("~/bundles/jqPlotJqueryPlugins")}

我收到以下错误

Dynamic view compilation failed.
The name 'Scripts' does not exist in the current context
The name 'Scripts' does not exist in the current context
The name 'Scripts' does not exist in the current context

它不起作用。这个的正确语法是什么?

还有什么语法在页面上包含引用?就像在剃刀中一样,我们使用@using Blah.Blah

1 个答案:

答案 0 :(得分:0)

ScriptsStyles类是System.Web.Optimization命名空间中的静态对象,因此您需要做的就是引用此命名空间,您可以使用它们。将其添加到Web.config中的spark部分:

<add namespace="System.Web.Optimization" />

然后你可以这样做:

${Scripts.Render("~/js/jquery")}
${Scripts.Render("~/js/jqueryval")}
${Scripts.Render("~/js/application")}
<use content="scripts"/>