Daryl1976
Daryl1976

Reputation: 745

MVC3 Razor Views Intellisense not detecting model object

I've been having an issue with mvc views on our website, where the view doesn't seem to detect the model type. I'll get an error message like 'model doesn't exist in the current context.', and and I'll get a red line under the model. It doesn't detect classes in the model either, and will try put an error line underneath the Html helpers. However, when I build the project and run it, it works fine. I've tried numerous suggestions on Stack Overflow, most involving changes to the config files, however nothing works. Here is what I have in the system.web section of my web.config:

 <customErrors mode="On" defaultRedirect="~/Error/ShowError">

    <siteMap defaultProvider="AgilitySiteMapProvider">
        <providers>
            <add name="AgilitySiteMapProvider" type="Agility.Web.Providers.AgilitySiteMapProvider, Agility.Web" />
        </providers>
    </siteMap>

    <pages>
        <namespaces>
            <add namespace="System.Web.Helpers" />
            <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.WebPages" />
            <add namespace="Agility.Web" />
            <add namespace="Agility.Web.Mvc" />
    <add namespace="CineplexWebsite.Helpers" />
        </namespaces>
        <controls>
            <add tagPrefix="Agility" assembly="Agility.Web" namespace="Agility.Web.Controls" />
            <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
            <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        </controls>
    </pages>

    <compilation debug="true" targetFramework="4.0">
  <assemblies>
    <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
  </assemblies>
</compilation>

<authentication mode="None">

</authentication>

and here is what I have in my views web.config

<system.web>

 <customErrors mode="On" defaultRedirect="~/Error/ShowError">

    <siteMap defaultProvider="AgilitySiteMapProvider">
        <providers>
            <add name="AgilitySiteMapProvider" type="Agility.Web.Providers.AgilitySiteMapProvider, Agility.Web" />
        </providers>
    </siteMap>

    <pages>
        <namespaces>
            <add namespace="System.Web.Helpers" />
            <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.WebPages" />
            <add namespace="Agility.Web" />
            <add namespace="Agility.Web.Mvc" />
    <add namespace="CineplexWebsite.Helpers" />
        </namespaces>
        <controls>
            <add tagPrefix="Agility" assembly="Agility.Web" namespace="Agility.Web.Controls" />
            <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
            <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        </controls>
    </pages>

    <compilation debug="true" targetFramework="4.0">
  <assemblies>
    <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
  </assemblies>
</compilation>

<authentication mode="None">

</authentication>

Any idea what is causing this? Am I missing a dll reference?

Upvotes: 1

Views: 2506

Answers (1)

Jeyhun Rahimov
Jeyhun Rahimov

Reputation: 3787

In your project there are 2 web.config files:

  • in root of project
  • in Views folder

You should add your <add namespace="CineplexWebsite.Helpers" /> model namespace into config file in Views folder. Usually, it not regocnized. Close and open project again, then it will regocnize.

Upvotes: 2

Related Questions