Reputation: 1941
I compiled my Razor Views with MvcRazorClassGenerator and like here: http://www.chrisvandesteeg.nl/2010/11/22/embedding-pre-compiled-razor-views-in-your-dll and in my view was source:
<h2>Hello!</h2>
<p>@Html.TextBox("hello", viewModel.foo)</p>
This tool generated .cs file with code:
WriteLiteral(" \r\n<h2>Hello!</h2>\r\n<p>");
Write(Html.TextBox("hello", viewModel.foo));
WriteLiteral("</p>");
But i have an error:
'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?)
Is it possible to use HtmlHelpers in .cs files like this?
Upvotes: 1
Views: 1502
Reputation: 244757
You are missing a reference to the namespace System.Web.Mvc.Html
. To add it, you can use @using System.Web.Mvc.Html
to your Razor file. Or you could add it to your web.config.
Upvotes: 3