1

I have migrated my project from MVC 4.0 to MVC 5.1. I have followed all the steps as mentioned here http://www.asp.net/mvc/tutorials/mvc-5/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2

Afrer that I have installed Vs 2013 SP1.

My project compiles without any issue and runs as expected. But When I open any .cshtml file i'm seeing the following error

The type arguments for method 'System.Web.Mvc.Html.DisplayExtensions.DisplayFor<TModel,TValue>(System.Web.Mvc.HtmlHelper<TModel>, 
  System.Linq.Expressions.Expression<System.Func<TModel,TValue>>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

I tried the following links, no luck.

MVC 5 -> MVC 5.1 Migration. Intellisense issues

mvc 3 to mvc 5 migration razor syntax issue

Any idea?

Community
  • 1
  • 1
Yass
  • 592
  • 1
  • 8
  • 30

2 Answers2

2

Ok, atlast I found a solution. But really not sure whether this is what causing the issue. When I looked the web.config file, all the dependentAssembly old version starts with 0.0.0.0. When I created a brand new MVC 5 project, the section starts with 1.0.0.0, when I changed them the above mentioned errors are gone.

But still I'm not convinced with this solution, if anyone find the root cause it'll help us.

<dependentAssembly>
        <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="1.0.0.0-5.1.0.0" newVersion="5.1.0.0" />
      </dependentAssembly>
Yass
  • 592
  • 1
  • 8
  • 30
0

All this means is that you're passing ambiguous parameters to DisplayFor. In particular there's an override that accepts a String as a second parameter, in which case, it's a name of a template that should be used to render it, or it could take an Object as a second parameter, in which case, it's extra view data that should be passed to the default template.

If you do something like pass in a "string" from ViewBag, like:

@Html.DisplayFor(m => m.Something, ViewBag.UseThisTemplate)

You're actually passing an object because ViewBag is not typed. This is just one example, but the long and short is that you're just not being explicit enough about what parameters you're passing and what their types are.

Chris Pratt
  • 232,153
  • 36
  • 385
  • 444