MVC5用VB.NET:" BC30451:'ViewData的“未声明"。切换到调试配置时 [英] MVC5 with VB.NET: "BC30451: 'ViewData' is not declared." when switching to Debug configuration

查看:1557
本文介绍了MVC5用VB.NET:" BC30451:'ViewData的“未声明"。切换到调试配置时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有当前发行配置设置MVC5项目和它的作品100%。然而,当我切换项目配置,从发布到调试,然后一切都错了......即使我切换回发布模式,一切仍然是断开的。只有这样,我能得到这个项目再次合作是从备份中恢复。

I have a MVC5 project that is currently set on the "Release Configuration" and it works 100%. However, as soon as I switch the project configuration from Release to Debug, then everything goes wrong... even if I switch it back to Release mode, everything is still broken. Only way I can get the project working again is to restore from a backup.

下面是发生了什么。
首先,在运行项目时,我收到以下错误:

Here are what is happening. Firstly, when running the project, I get the following error:

BC30451:ViewData的未声明。它可能无法访问由于其
  保护级别。

BC30451: 'ViewData' is not declared. It may be inaccessible due to its protection level.

如果我打开与Visual Studio 2013的项目中的任何观点,我可以看到,各种东西都被标记为喜欢的ViewData,HTML,URL等错误。

If I open any view in the project with Visual Studio 2013, I can see that all sorts of things are marked as errors like ViewData, Html, Url, etc.

当在视图中提到@Html或@ViewData,通常指的是视图的基类(WebViewPage)的.html和.ViewData属性。但是,如果我开始打字@Html。在任何意见,我可以,因为它是指System.Web.Webpages.Html命名空间,而不是WebViewPage.Html属性自动完成看。这是因为,如果视图不是从System.Web.Mvc.WebViewPage类继承。

When referring to @Html or @ViewData in the view, it normally refers to the .Html and .ViewData properties of the view's base class (WebViewPage). However, if I start typing "@Html." in any of the views, I can see in the autocomplete that it is referring to the System.Web.Webpages.Html namespace instead of the WebViewPage.Html property. It is as-if the view isn't inheriting from the System.Web.Mvc.WebViewPage class.

任何指导,在那里我可以开始寻找得到这个固定的或为什么发生这种情况?

Any guidance as to where I can start looking to get this fixed or why this is happening?

编辑:
所以,因为没有人回应,我经历了很长的路去了。我创建了一个全新的MVC5项目,通过添加所有的Nu​​Get包,然后简单地从旧项目到新复制我的所有文件过去,现在它的作品。

So since nobody responded, I went through the long way. I created a brand new MVC5 project, added all the packages via Nuget and then simply copied all my files over from the old project to the new one and now it works.

没有任何人有任何想法究竟发生了什么可能会造成这个?我不想在将来再次经历这一切的麻烦,如果该项目再次突然决定停止工作。

Does anybody have any idea what the heck could be causing this? I don't want to go through all this trouble again in the future if the project again suddenly decides to stop working.

推荐答案

好吧,我想我已经找到了事业的一部分在这里。事情是,因为原来的code是有效(正确编译和智能它拾起)和code用于工作,然后突然有一天的编译,它只是停止工作了。

Ok, I think I've found part of the cause here. Thing is, since the original code is valid (it compiles correctly and intellisense picks it up) and the code used to work and then all of a sudden, one day after compiling, it just stops working.

总之,在视图中,指定ModelType时,如果不使用全名,可发生或最终出现此错误。
例如,使用

Anyway, in the view, when specifying the ModelType, if you don't use the full name, this error can occur or occurs eventually. For example, using:

@ModelType Models.SomeNamespace.SomeClass

将导致错误(即使根命名空间的项目是MyProject的),它可以简单的通过指定完整的命名空间和类名是固定的。

will cause the error (even though the Root Namespace for the project is "MyProject") and it can be fixed by simply specifying the full namespace and class name.

@ModelType MyProject.Models.SomeNamespace.SomeClass

这篇关于MVC5用VB.NET:" BC30451:'ViewData的“未声明"。切换到调试配置时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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