具有自定义 HTML 帮助程序的 Spark View 引擎
我已将一些自己的帮助程序添加到项目中的 System.Web.Mvc 中,并使其与默认的 asp.net mvc 视图引擎一起使用。通过定义助手,就像
namespace System.Web.Mvc
{
public static class XSSHelper
{
public static string h(this HtmlHelper helper, string input)
{
return AntiXss.HtmlEncode(input);
}
public static string Sanitize(this HtmlHelper helper, string input)
{
return AntiXss.GetSafeHtml(input);
}
public static string hscript(this HtmlHelper helper, string input)
{
return AntiXss.JavaScriptEncode(input);
}
}
}
我使用 <%= Html.h("
some string
") %>
现在我正在使用 Spark 视图引擎一样似乎无法让它发挥作用。我收到以下错误:
“System.Web.Mvc.HtmlHelper”不包含“h”的定义,并且找不到接受“System.Web.Mvc.HtmlHelper”类型的第一个参数的扩展方法“h”(您是否缺少using 指令还是程序集引用?)'
如何让 Spark 查看其他帮助程序?
编辑:我还添加了 _global.spark 与
无济于事
I've added some of my own helpers to the System.Web.Mvc within my project and got it working with the default asp.net mvc view engine. By defining the helper like
namespace System.Web.Mvc
{
public static class XSSHelper
{
public static string h(this HtmlHelper helper, string input)
{
return AntiXss.HtmlEncode(input);
}
public static string Sanitize(this HtmlHelper helper, string input)
{
return AntiXss.GetSafeHtml(input);
}
public static string hscript(this HtmlHelper helper, string input)
{
return AntiXss.JavaScriptEncode(input);
}
}
}
I called it using <%= Html.h("<h1>some string</h1>") %>
Now that I am using the spark view engine I cannot seem to get this to work. I receive the following error:
'System.Web.Mvc.HtmlHelper' does not contain a definition for 'h' and no extension method 'h' accepting a first argument of type 'System.Web.Mvc.HtmlHelper' could be found (are you missing a using directive or an assembly reference?)'
How can I get Spark to see the additional helpers?
EDIT: I've also added _global.spark with <using namespace="myApp" />
to no avail
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当我的项目全面展开时,我的 _global.spark 通常最终看起来像这样。我建议在一开始就这样做以避免这些问题:
My _global.spark usually ends up looking like this by the time my project is in full swing. I recommend just doing this at the beginning to avoid these issues:
确保 System.Web.Mvc.HtmlHelper 已在 Spark 配置部分的 web.config 中注册。
Make sure that
System.Web.Mvc.HtmlHelper
is registered in your web.config within the spark config section.在 _global.spark 文件中添加
似乎已经解决了这个问题。Added
<using namespace="System.Web.Mvc" />
in the _global.spark file seems to have solved this problem.