问题背后的Html.TextBox(Helper)问题

时间:2011-08-28 17:41:27

标签: asp.net-mvc razor html-helper

我用MvcRazorClassGenerator编译了我的Razor视图,就像这里:http://www.chrisvandesteeg.nl/2010/11/22/embedding-pre-compiled-razor-views-in-your-dll 在我看来是来源:

<h2>Hello!</h2>
<p>@Html.TextBox("hello", viewModel.foo)</p>

此工具生成.cs文件,代码为:

WriteLiteral(" \r\n<h2>Hello!</h2>\r\n<p>");
Write(Html.TextBox("hello", viewModel.foo));
WriteLiteral("</p>");

但我有一个错误:

'System.Web.Mvc.HtmlHelper<dynamic>' does not contain a definition for 'TextBox' and no extension method 'TextBox' accepting a first argument of type 'System.Web.Mvc.HtmlHelper<dynamic>' could be found (are you missing a using directive or an assembly reference?)

是否可以在.cs文件中使用HtmlHelpers?

1 个答案:

答案 0 :(得分:3)

您缺少对命名空间System.Web.Mvc.Html的引用。要添加它,您可以将@using System.Web.Mvc.Html用于Razor文件。或者你可以add it to your web.config