简体   繁体   English

在我的混合项目中,我无法创建视图包

[英]In my hybrid project i can not create a viewbag

I had a classical web forms application. 我有一个经典的Web表单应用程序。 I wanted to be add mvc 4 in it. 我想在其中添加mvc 4。

For this manner i added necessary references. 通过这种方式,我添加了必要的参考。 i made some changes in web.config 我在web.config中做了一些更改

and i created two folders named Views and Controllers. 我创建了两个名为“视图”和“控制器”的文件夹。 And then i added a view in Views folder. 然后我在“视图”文件夹中添加了一个视图。 The code like this 像这样的代码

 @{
 ViewBag.Title = "About";
}

<ul>
    <li>@Html.ActionLink("Home", "Index", "Home")</li>
    <li>@Html.ActionLink("About", "About", "Home")</li>
    <li>@Html.ActionLink("Contact", "Contact", "Home")</li>
</ul>

but im having errors al the time. 但是我总是有错误。

The name ViewBag does not exist in current context. 名称ViewBag在当前上下文中不存在。

what can be problem. 可能是什么问题。

you have missed some Web.config int the view folder /Views/Web.Config 您错过了一些Web.config int视图文件夹/Views/Web.Config

 <configuration>

 <system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

  <pages pageBaseType="System.Web.Mvc.WebViewPage"> // <-- this line and contents are important
    <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>

try this and let me know 试试这个,让我知道

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM