我在我的項目中添加了一些我自己的助手到System.Web.Mvc,並讓它使用默認的asp.net mvc視圖引擎。通過定義像帶有自定義HTML助手的Spark View引擎
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("<h1>some string</h1>") %>
現在,我使用的火花視圖引擎我似乎無法得到這個工作。我收到以下錯誤:
'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?)'
如何獲取Spark以查看其他幫助?
編輯:我還添加了_global.spark與<using namespace="myApp" />
無濟於事
收到的錯誤「HtmlHelper是一種類型而不是命名空間」 – jdiaz 2010-07-28 08:08:52