This project is read-only.

(Bug) HtmlHelper Not Working


When I use any of the HtmlHelpers in the template I am trying to compile I get errors.
for example: @Html.LabelFor(d => d.SomeProperty)

Error I get:
Unable to compile template. The name 'Html' does not exist in the current context

Other compilation errors may have occurred. Check the Errors property for more information

Razor I am building:

@model Testing.Models.HomeModel
@using System.Web.Mvc
@using System.Web.Mvc.Ajax
@using System.Web.Mvc.Html
@using System.Web.Routing
@using System
@using System.Collections.Generic
@using System.IO
@using System.Linq
@using System.Net
@using System.Web
@using System.Web.Helpers
@using System.Web.Security
@using System.Web.UI
@using System.Web.WebPages
@using System.Web.WebPages.Html

Layout = null;

<!DOCTYPE html>
<head> <meta name=""viewport"" content=""width=device-width"" /> <title>Index</title> </head> <body>
@Html.LabelFor(d => d.Name)



DotNetRockStar wrote Mar 25, 2014 at 3:01 PM

Other @using statements seem to work just fine. For some reason the context is not being honored for the extensions methods in mvc4.

Check it out:
System.Web.Mvc.Html.LabelExtensions.LabelFor(this HtlmHelper<TModel> html .....)
It appears that HtmlHelper context is not in scope during/after the compilation of the razor template?

The @Html aspect is a static HtmlHelper value that exists in templates you create (when using the default engine). Is there any way I can get this injected into the template during creation so I can use these helpers?