ViewBag name does not exist in the current mvc 4 context

I have a problem with my strongly typed view. I try my best and read a lot about the web.config related. I cannot find the problem. below in terms of.

@model IEnumerable<RoomsForRent.Domain.Entities.Room>

@{
    ViewBag.Title = "Home";
}

      

My domain object is RoomsForRent.Domain.Entities.Room

showing an unknown item. Display ViewBag, @model does not exist. From the web.Config of my view.

<configSections>
    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
      <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=2.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=4.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" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>

  <appSettings>
    <add key="webpages:Enabled" value="false" />
  </appSettings>

      

Please, is there anything I can't see? I recently deleted and restarted the project from the beginning, but the same error is displayed. I am embarrassed.

+3


source to share


2 answers


There was the same problem. Information within the project is deprecated regarding DLL files. Made these changes.

1) Inside main web.config

<appSettings>
    <add key="webpages:Version" **value="1.0.0.0"**/> --> value="2.0.0.0"
</appSettings>

      

2) Inside View web.config changed all version values ​​to current MVC version



<pages
validateRequest="false"
pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=4.0.0.0, ....
pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=4.0.0.0, ....
userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=4.0.0.0, ...>
  <controls>
<add assembly="System.Web.Mvc, Version=4.0.0.0.,... />

      

  

In addition, in order for the project to receive the changes, it had to restart it. After rebooting everything worked fine.

Hope it helps.

+3


source


I would first check if there is a Web.config file in. / Views / Web.config



-1


source







All Articles