Html.LabelFor error

164 views
Skip to first unread message

Kevin Pratt

unread,
May 30, 2010, 10:30:38 AM5/30/10
to nhaml-users
I was trying out nhaml and was converting one of my views that
contained :

<fieldset>
<legend>Fields</legend>

<div class="editor-label">
<%= Html.LabelFor(model => model.UserName) %>
</div>
<div class="editor-field">
<%= Html.EditorFor(model => model.UserName) %>
<%= Html.ValidationMessageFor(model => model.UserName)
%>
</div>

I converted it to :

%fieldset
%legend Fields
.editor-label
= Html.LabelFor(model => model.UserName)
.editor-field
= Html.EditorFor(model => model.UserName)
= Html.ValidationMessageFor(model => model.UserName)


However I'm getting an error message that looks something like:
c:\Documents and Settings\kpratt\Local Settings\Temp\ecjc94rf.
0.cs(56,43) : error CS1061: 'System.Web.Mvc.HtmlHelper' does not
contain a definition for 'LabelFor' and no extension method 'LabelFor'
accepting a first argument of type 'System.Web.Mvc.HtmlHelper' could
be found (are you missing a using directive or an assembly reference?)

I can't seem to use any of the "For" methods.

My web config looks like:
<section name="nhaml"
type="NHaml.Configuration.NHamlConfigurationSection, NHaml" />
<nhaml autoRecompile="true" templateCompiler="CSharp3"
encodeHtml="true">
<assemblies>
<clear />
<add assembly="System, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=B77A5C561934E089" />
</assemblies>
<namespaces>
<clear />
<add namespace="System.Web" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Collections" />
<add namespace="System.Collections.Generic" />
</namespaces>
</nhaml>

If this is a limitation is there another way to use the built in
helpers?

Thanks
Kevin

Steve Wagner

unread,
May 31, 2010, 7:09:19 AM5/31/10
to nhaml...@googlegroups.com
Hi Kevin. The current stable version of NHaml is build against Mvc 1.0.
LabelFor and co are extension from Mvc 2.0. I think there are some
patches for that in the latest trunk. You can grab it form here:

http://github.com/NHaml/NHaml

-Steve

SandRock

unread,
Jul 18, 2010, 11:02:22 AM7/18/10
to nhaml-users

SandRock

unread,
Jul 8, 2010, 7:35:18 PM7/8/10
to nhaml-users
Hi,
I have the same problem. MVC2 methods are not referenced in the
generated views.
Reply all
Reply to author
Forward
0 new messages