名称ViewBag并不在当前上下文中的MVC 4存在 [英] The name ViewBag does not exist in the current context mvc 4

查看:115
本文介绍了名称ViewBag并不在当前上下文中的MVC 4存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的强类型视图的问题。我尝试一切可能与有关相关的web.config中没有很多阅读。我coudn't找到问题。下面是从视图。

I am having an issue with my strongly typed view. I try everything possible and did read alot about the web.config related . I coudn't find the issue. below is from the view.

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

@{
    ViewBag.Title = "Home";
}

我的域实体 RoomsForRent.Domain.Entities.Room 显示未知因素。的ViewBag,@model是表示不存在。从我的观点的Web.config。

My Domain entity RoomsForRent.Domain.Entities.Room shows unknown element. The ViewBag, @model is showing 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 am missing ? I recently deleted and restart the project from beginning , yet the same error is showing. I am confused.

推荐答案

假如同样的问题。项目内幕信息的参考dll文件已经过时。做出这些改变。

Had same problem. Information inside of project were outdated in reference to dll files. Made these changes.

1)内部主要的web.config

1) Inside main web.config

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

2)内部视图web.config中改变了所有版本值,以目前的MVC版本

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.,... />


    

此外,为了使项目获得的变化不得不重新启动它。重新启动所有工作正常后。

Also, in order for project to get changes had to restart it. After restarting all was working fine.

希望它帮助。

这篇关于名称ViewBag并不在当前上下文中的MVC 4存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆