视图数据和当前上下文中不存在模型 [英] ViewData & Model does not exist in the current context

查看:161
本文介绍了视图数据和当前上下文中不存在模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用VS 2017 EF Core的.Net Core 1.1项目.创建新视图时,我在ViewData,Model甚至@model上收到在当前上下文中不存在的错误.在尝试解决该问题时,我最终更新了我的软件包,这只会给我带来更多的错误来解决.由于更新,我没有运行.Net Core 2.0.我项目中的其他视图没有此问题.我只创建了另一个视图,最终遇到了同样的问题,但是在@model上就消失了……不要问我如何或为什么.对于这种模型,我似乎找不到解决方案.我重建了项目.我删除了视图并重新创建它,但无济于事.现在,@model似乎很好,但是找不到视图模型,并且我的视图中没有任何智能提示. ViewImports文件包含必需的所有内容.我已经在视图中对模型进行了完全限定,但是这没有帮助.我有36个错误,其中大多数都指向第1行,这是我的"@model TournamentScheduleViewModel"语句.因此,我认为缺少了一些东西.在出现此问题之前,我没有对其进行任何更新.下面是我遇到问题的视图的快照,以及在错误列表中看到的一些错误之一.我已经在网上搜索了,但是没有找到能解决我问题的任何东西.任何帮助将不胜感激.这让我发疯,我已经准备好继续进行我的项目.如果您想查看更多代码或信息,请告诉我.谢谢.

I have a .Net Core 1.1 project using VS 2017 EF Core. When I created a new view, I received the does not exist in current context error on the ViewData, the Model, and even the @model. In trying to fix the problem, I ended up updating my packages which only gave me more errors to resolve. I'm not running .Net Core 2.0 because of the update. The other views in my project are not having this issue. I created only one other view and I ended up having the same problem with it, but just on @model and it went away...don't ask me how or why. For this model, I can't seem to find a solution. I rebuilt the project. I deleted the view and recreated it to no avail. Now, @model seems to be fine, but the view model is not found and I don't have intellisense within my view for anything. The ViewImports file has everything in it that's required. I have fully qualified the model in the view and that doesn't help. I have 36 errors and most of them are pointing to line 1, which is my "@model TournamentScheduleViewModel" statement. So, I figure something is missing. I hadn't done any updates to it prior to this problem. Below is a snapshot of the view I'm having trouble with and one of some of the errors I'm seeing in my error list. I've searched the web and haven't found anything that resolves my problem. Any assistance would be greatly appreciated. This is driving me nuts and I'm ready to proceed with my project. If you'd like to see more code or info, please let me know. Thanks.

此外,忘了提一下,当我按F5或ctrl-F5时,即使出现所有错误,该网站也会出现在浏览器中.我可以单击并仍然查看页面,只有一部分,因为它不能完全正常工作.

Also, forgot to mention that when I press F5 or ctrl-F5, the website comes up in the browser even with all of the errors. I can click and still view the page, only a portion as it's not entirely working properly.

推荐答案

目前尚不确定为什么我的视图无法识别我的视图模型,模型"和"ViewData"是什么问题,但是我重新开始并创建了另一个.net core 1.1项目,并将所有文件和修改内容复制到了新项目中,一切正常.导致我遇到很多问题的观点就像灵丹妙药一样.

Not sure at this point what the problem was regarding why my view model, 'Model', and 'ViewData' wasn't recognized in my view, but I started over and created another .net core 1.1 project and copied all of the files and modifications over to the new project and everything works fine. The view that was causing me so many problems works like a charm.

这篇关于视图数据和当前上下文中不存在模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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