0

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.

2
  • Cannot reproduce from my side. But I think you can try to rebuild the project. Commented Jan 3, 2023 at 6:54
  • import model with using statement in cshtml file Commented Jan 3, 2023 at 16:33

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.