vb.net asp.net mvc 5 'ModelType' 未声明
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24924953/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
asp.net mvc 5 'ModelType' is not declared
提问by brando
I recently did a NuGet package-update on two of my projects. So I am using Microsoft.AspNet.Mvc version 5.2.0. One project is working great, the other has something out of whack because I cannot now create strongly typed razor views. Here is a snip from one of my views:
我最近对我的两个项目进行了 NuGet 包更新。所以我使用的是 Microsoft.AspNet.Mvc 5.2.0 版。一个项目运行良好,另一个项目出现异常,因为我现在无法创建强类型的剃刀视图。这是我的一个观点的片段:
@ModelType MyServiceLibrary.EmailTemplateModelObject
Dear @Model.FirtName,<br><br>
I get the following error:
我收到以下错误:
'ModelType' is not declared. It may be inaccessible due to its protection level.
未声明“ModelType”。由于其保护级别,它可能无法访问。
Pretty much exactly what what is referenced in this question: asp.net mvc 3 'ModelType' is not declared
几乎正是这个问题中引用的内容: asp.net mvc 3 'ModelType' is not notice
I have attempted to implement the recommended fix but no luck. I am using a vb.net environment. Here is what i have in my ~/Views/Web.config:
我曾尝试实施推荐的修复程序,但没有成功。我正在使用 vb.net 环境。这是我的 ~/Views/Web.config 中的内容:
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.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=5.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.Optimization"/>
<add namespace="System.Web.Routing" />
</namespaces>
</pages>
</system.web.webPages.razor>
Can anybody see what i'm doing wrong here?
有人能看到我在这里做错了什么吗?
回答by Zev Spitz
We encountered the same issue under VS 2012. We resolved it by:
我们在 VS 2012 下遇到了同样的问题。我们通过以下方式解决了它:
- Installing ASP.NET and Web Tools 2013.1 for Visual Studio 2012
- Installing Entity Framework 6 Tools for Visual Studio 2012 & 2013
- Taking the steps in the other answer-- modifying the
web.configand resetting all settings
- 为 Visual Studio 2012安装ASP.NET 和 Web Tools 2013.1
- 为 Visual Studio 2012 和 2013安装Entity Framework 6 工具
- 采取其他答案中的步骤- 修改
web.config并重置所有设置
NB: Before resetting, I exported the settings; after the reset, I reimported all the settings except for the Web Projectscategory, and everything still works.
注意:在重置之前,我导出了设置;重置后,我重新导入了除Web 项目类别之外的所有设置,一切仍然有效。
回答by Carl Onager
I had a very similar problem when creating a new MVC 5 project although it was the 'Layout' that was not declared.
我在创建一个新的 MVC 5 项目时遇到了一个非常相似的问题,尽管它是未声明的“布局”。
I opened the TOOLS > NuGet Package Manager > Manage NuGet Packages for Solutiom item, selected 'Installed packages' and clicked 'Updaet All' which fixed my problems by updating all of the various DLLs and web.config files to the latest version.
我打开了 TOOLS > NuGet Package Manager > Manage NuGet Packages for Solutiom 项,选择了“已安装的包”并单击“全部更新”,它通过将所有各种 DLL 和 web.config 文件更新到最新版本来解决我的问题。
回答by Mike Schall
In my case, I was adding MVC5 to a project using "Manage Nuget Packages..." that only had WebApi when created. Many other pieces of MVC were missing (RouteConfig.vb, reference to System.Web.Routing, Web.config inside Views folder, ...), but the key to get rid of this issue was ensuring the ~/web.config (the web.config in the root of the site) had an appSettings node that included:
就我而言,我使用“管理 Nuget 包...”将 MVC5 添加到一个项目中,该项目在创建时只有 WebApi。MVC 的许多其他部分都丢失了(RouteConfig.vb,对 System.Web.Routing 的引用,Views 文件夹中的 Web.config,...),但摆脱这个问题的关键是确保 ~/web.config (站点根目录中的 web.config)有一个 appSettings 节点,其中包括:
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
</appSettings>
Once they were added, I restarted VS 2013 and everything worked fine.
添加它们后,我重新启动了 VS 2013,一切正常。
回答by Chalky
I had the same issue with VS 2013. I closed Visual Studio and re-opened it, problem gone.
我在 VS 2013 中遇到了同样的问题。我关闭了 Visual Studio 并重新打开它,问题消失了。
回答by brando
Well, I was able to narrow the problem to the subject of "intellisense not working for MVC5" and found a very simple fix that solved my problems:
好吧,我能够将问题缩小到“智能感知不适用于 MVC5”的主题,并找到了一个非常简单的修复方法来解决我的问题:
Step 1: Update webpages:Version
第 1 步:更新网页:版本
Change
改变
<add key="webpages:Version" value="2.0.0.0" />
to
到
<add key="webpages:Version" value="3.0.0.0" />
Step 2: Resetting my settings.
第 2 步:重置我的设置。
Tools > Import and Export Settings... > Reset all settings
工具 > 导入和导出设置... > 重置所有设置
Step 3: closed all files, restarted Visual Studio and humpty dumpty was back together again!
第 3 步:关闭所有文件,重新启动 Visual Studio,然后 humpty dumpty 又回来了!
Source: Visual Studio 2013 IntelliSense stops working for ASP.NET MVC5 Controllers

