I have a strongly-typed view with a @model declaration:
@model MyViewModel
When using extension methods like this in my Razor views:
@Html.TextBoxFor(m => m.Foo)
Visual Studio shows errors like this:
The type arguments for method ‘System.Web.Mvc.Html.InputExtensions.TextBoxFor<TModel,TProperty>(System.Web.Mvc.HtmlHelper<TModel>, System.Linq.Expressions.Expression<System.Func<TModel,TProperty>>)’ cannot be inferred from the usage. Try specifying the type arguments explicitly.
These are only errors shown for the editor window; the view renders just fine at runtime.
Does this happen for everyone, or is there something I can do to make the Razor editor work better?
Thanks to this answer, I found the solution. In my web.config, once I specified a
targetFrameworkattribute in mysystem.web/compilationconfig section, all of those nasty warnings disappeared. Previously, notargetFrameworkwas specified. Strangely, Visual Studio doesn’t just use the target framework of your project: