Tuesday, June 9, 2015

'System.Web.WebPages.Html.HtmlHelper' does not contain a definition for 'DropDownListFor' and no extension method 'DropDownListFor' accepting a first argument of type 'System.Web.WebPages.Html.HtmlHelper' could be found (are you missing a using directive or an assembly reference?)

If you are working on Visual Studio 2013 Premium and started to work on MVC 4 or 5 project. You will be probably experiencing this error while building your solution. MVC Razor mark ups were not recognized and intellisence were not working. I think I have figure out the fix.

I tried below options from several posts (mentioned in the end of this post)

Attempt 1:

1.Check /Views/ web.config
2.Check the Razor reference syntax is like below

<configSections>
    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
      <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    </sectionGroup>
  </configSections>
 
  <system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.Optimization" />
        <add namespace="Orca.Web" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>

(I'm working on MVC 5)

Attempt 2:

Clean the solution and close VS 2013 premium. Deployed Update 4 for Visual Studio 2013 Premium. Start the VS and clean the solution and rebuild. Yup That's it! Worked successfully.


No comments:

Post a Comment