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

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

问题描述

我有一个使用 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.

推荐答案

目前不确定问题是什么,为什么我的视图模型、'Model' 和 '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天全站免登陆