2011-10-31 70 views
0

我想构建一个自定义HTML帮助程序。以下几个教程,我的代码 -自定义MVC3帮助程序的语法错误

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

任何关于我的语法错误是什么的建议?

回答

0

你的代码建议助手被称为“BuildJsonPrototype”,然而在你使用'BuildJsonModel'的标记中?这是问题吗?

+0

它总是很明显的东西,你看不到。谢谢。 –

+0

没问题 - 我们都曾经在那里太多次:) – glosrob