ViewData & Model does not exist in the current context

假如想象 提交于 2019-12-11 15:13:38

问题


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.

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.


回答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.



来源:https://stackoverflow.com/questions/47162171/viewdata-model-does-not-exist-in-the-current-context

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!