index.g.cshtml在哪里 [英] Where is index.g.cshtml

查看:352
本文介绍了index.g.cshtml在哪里的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试完成本教程,(

I am trying to work through this tutorial, (ASP.Net Core Razor Pages) but (often) when I build the solution, I get a CS0234 error stating that a namespace is missing from file 'Index.g.cshtml.cd'...….but where does this file exist? I have tried 1. All the build/clean/rebuild solution options. 2. I have restarted Visual Studio 3. I have deleted the DEBUG files and restarted VS and FINALLY 4. I have restarted my PC. The ONLY solution that seems to work, is to delete the entire solution/project and start again.

当然必须对此进行修复吗? 你能帮忙吗?

Surely there must be a fix for this? Can you assist?

推荐答案

如果错误表明xxx.g.cshtml.cs中缺少using指令或命名空间,则通常意味着在视图中直接存在一个指令(.cshtml.vbhtml),编译器无法解析.

If an error says a using directive or namespace is missing from xxx.g.cshtml.cs, that usually means, that there is a directive directly in the view (.cshtml or .vbhtml), that the compiler cannot resolve.

就我而言,我在局部视图中有以下陈述:

In my case I had the following statement in a partial view:

@inject UserManager<AppUser> UserManager

然后,我将Web应用程序Namespace.Web.AppUser中的AppUser类重构为Namespace.Entities.AppUser,这随后导致了该错误.

I then went along and refactored the AppUser class from the web application Namespace.Web.AppUser into Namespace.Entities.AppUser, which then was causing that error.

有多种解决方法. 最简单的方法是使用完全限定的类型名称空间:

There are different ways to resolve this. The easiest way is to use a fully qualified type namespace:

@inject UserManager<Namespace.Entities.AppUser> UserManager

如果在另一个项目中,请不要忘记添加对另一个项目的引用. 或者:添加一条using语句:

And do not forget to add a reference to the other project, if it is in another project. Or: add a using statement:

@using Namespace.Entities;

或:将上述using语句添加到您的~\Views\_ViewStart.cshtml中.这将使该类在所有视图中可用.

Or: Add the using statement above to your ~\Views\_ViewStart.cshtml. This will make that class available in all views.

这篇关于index.g.cshtml在哪里的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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