这个名字“模式”并不在MVC3目前的情况下存在 [英] The name 'model' does not exist in current context in MVC3

查看:189
本文介绍了这个名字“模式”并不在MVC3目前的情况下存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在项目中增加了一个CSHTML页面。当我试图下面的声明添加到它,我得到一个错误:这个名字'模式'不当前环境的存在

I added a cshtml page in an project. When I tried to add the following declaration to it, I get an error: "The name 'model' does not exist in current context".

@model xyz.abc.SomeClass

我查了引用,个个都很到位。我加在视图文件夹一个web.config,但这并没有解决它。

I checked the references, all of them are in place. I added a web.config in view folder, but that didn't fix it.

有什么我失踪?

推荐答案

更新:如果您正在使用MVC的更新版本,同样的过程也适用,只是一定要使用Web正确的版本号。配置的<主机方式>

好吧,我发现自己遇到了你做同样的事情,有点进一步研究后,我发现是什么问题!

Well, I found myself experiencing the same thing you did, and after a bit further research, I found out what the problem is!

您需要包括对浏览文件夹的默认MVC3的web.config。 MVC3有二:一是在根为您的应用,以及一个用于views文件夹。这对包括命名空间的部分。要确保你看起来是这样的:

You need to include the default MVC3 web.config for the Views folder. MVC3 has two: one in the root for your application, and one for the views folder. This has a section for included namespaces. Be sure that yours looks something like this:

  <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">
      <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>

我建议你创建一个新的MVC3项目,那么就为您创建的web.config文件复制到你的意见文件夹中。

I suggest that you create a new MVC3 project, then just copy the web.config created for you into your views folder.

重要提示一旦你做到了这一点,你需要关闭该文件并重新打开它。瞧!智能感知!

Important Once you've done that, you need to close the file and reopen it. Voila! Intellisense!

这篇关于这个名字“模式”并不在MVC3目前的情况下存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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