Razan Al-Ahmad
Razan Al-Ahmad

Reputation: 1

Using @HTML.labelFor helper in ASP.NET MVC

I am creating a view for a model in ASP.NET MVC. I am using @HTML.LabelFor

@Html.LabelFor(m => m.Name, htmlAttributes: new { @class = "control-label col-md-2" })

but I am getting this error:

Error CS0411
The type arguments for method 'LabelExtensions.LabelFor<TModel, TValue>(HtmlHelper, Expression<Func<TModel, TValue>>, object)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

Upvotes: 0

Views: 131

Answers (1)

SNBS
SNBS

Reputation: 849

This is a strange error, but doing what it asks to do can help. Try specifying the type arguments explicitly:

@Html.LabelFor<YourModelType, TypeOfNameProperty>(m => m.Name, htmlAttributes: new { @class = "control-label col-md-2" })

Note: my experience (that knows lots of errors like this) tells me that this error will vanish after some time. During this time, you may use the code above. It's not more than a workaround.

Upvotes: 0

Related Questions