自定义MVC3帮助程序的语法错误

时间:2011-10-31 23:28:01

标签: asp.net-mvc-3

我正在尝试构建自定义HTML帮助器。以下几个教程,我的代码是 -

namespace System.Web.Mvc.Html 
{
    using System;
    using System.Web.Mvc;
    public static class HtmlHelpers
    {
        public static string BuildJsonPrototype(this HtmlHelper helper, string targetName)
        {
            var d = BuildJsonModel.Build( typeof(Int32), targetName);
            return d;
        }
    }
}

在我的Razor视图中,代码是 -

@using System.Web.Mvc.Html    
@Html.BuildJsonModel( "test")

当我尝试运行它时,我收到以下编译器错误 -

Compiler Error Message: CS1061: 'System.Web.Mvc.HtmlHelper<AutoBind.Models.ComplexModel>'
does not contain a definition for 'BuildJsonModel' and no extension method
'BuildJsonModel' accepting a first argument of type
'System.Web.Mvc.HtmlHelper <AutoBind.Models.ComplexModel>' could be found
(are you missing a using directive or an assembly reference?)

有关我的语法错误的建议吗?

1 个答案:

答案 0 :(得分:0)

您的代码建议帮助程序名为“BuildJsonPrototype”,但在您的标记中,您使用的是“BuildJsonModel”?这是问题吗?

相关问题