【发布时间】:2011-08-28 17:41:26
【问题描述】:
我使用 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?
【问题讨论】:
-
“您是否缺少 using 指令或程序集引用?”
-
在 Razor 中使用指令是
@using System.Web.Mvc.Html。程序集参考必须在您的项目中。但我认为如果默认情况下不包含该命名空间会很奇怪。另一种可能是web.config。 -
是的,我只是想写它。在这里找到:java2s.com/Open-Source/ASP.NET/Forum/openforum/OpenForum/Core/…。这个工具并没有编写所有指令,更多的指令你必须自己编写。谢谢。
标签: asp.net-mvc razor html-helper