星火视图引擎的自定义HTML助手 [英] Spark View Engine with custom HTML Helpers

查看:191
本文介绍了星火视图引擎的自定义HTML助手的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加了一些我自己的助手到System.Web.Mvc我的项目中,并得到其与默认asp.net MVC视图引擎的工作。通过定义像

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);
        }
    }
}

我把它叫做使用<%= Html.h(< H1>一些字符串< / 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'不包含'H',没有扩展方法'H',接受类型'System.Web.Mvc.HtmlHelper'的第一个参数的定义可以找到(是否缺少using指令或程序集引用?)

'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?

编辑:我还添加_global.spark与<采用命名空间=对myApp/> 无济于事

I've also added _global.spark with <using namespace="myApp" /> to no avail

推荐答案

我_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:

<use namespace="Spark"/>
<use namespace="System.Web.Mvc"/>
<use namespace="System.Web.Mvc.Ajax"/>
<use namespace="System.Web.Mvc.Html"/>
<use namespace="System.Web.Routing"/>
<use namespace="System.Linq"/>
<use namespace="System.Collections.Generic"/>

<use assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<use assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<use assembly="System.Web.Abstractions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<use assembly="System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<use assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<use assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<use assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<use assembly="System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />

这篇关于星火视图引擎的自定义HTML助手的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆