.Net Core 2.0找不到视图“索引" [英] .Net Core 2.0 The view 'Index' was not found
问题描述
我将.net core 2.0应用程序部署到IIS,但出现以下错误.
I deployed .net core 2.0 application to IIS and I get the following error.
InvalidOperationException:找不到视图索引".搜索了以下位置:/Views/Home/Index.cshtml/Views/Shared/Index.cshtml
InvalidOperationException: The view 'Index' was not found. The following locations were searched: /Views/Home/Index.cshtml /Views/Shared/Index.cshtml
这只是我用来测试Web部署的全新默认.net核心Web模板.我已经尝试了下面的代码,但这也不起作用.
This is just a brand new default .net core web template that I am using to test web deploy. I have tried the below code but that doesn't work either.
public static void Main(string[] args)
{
new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.Build()
.Run();
}
我有没有要离开的步骤
堆栈跟踪:
消息 InvalidOperationException:找不到视图索引".搜索了以下位置: /Views/Home/Index.cshtml /Views/Shared/Index.cshtml Microsoft.AspNetCore.Mvc.ViewEngines.ViewEngineResult.EnsureSuccessful(IEnumerable originalLocations)
Message InvalidOperationException: The view 'Index' was not found. The following locations were searched: /Views/Home/Index.cshtml /Views/Shared/Index.cshtml Microsoft.AspNetCore.Mvc.ViewEngines.ViewEngineResult.EnsureSuccessful(IEnumerable originalLocations)
InvalidOperationException: The view 'Index' was not found. The following locations were searched: /Views/Home/Index.cshtml /Views/Shared/Index.cshtml
Microsoft.AspNetCore.Mvc.ViewEngines.ViewEngineResult.EnsureSuccessful(IEnumerable<string> originalLocations)
Microsoft.AspNetCore.Mvc.ViewResult+<ExecuteResultAsync>d__26.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+<InvokeResultAsync>d__19.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+<InvokeNextResultFilterAsync>d__24.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResultExecutedContext context)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+<InvokeNextResourceFilter>d__22.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+<InvokeFilterPipelineAsync>d__17.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+<InvokeAsync>d__15.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Builder.RouterMiddleware+<Invoke>d__4.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware+<Invoke>d__7.MoveNext()
推荐答案
在我的情况下,我将ASP.Net Core MVC与VS2017配合使用,已将Index.cshtml
的生成操作设置为Content
,但仍然出现错误
In my case I'm using ASP.Net Core MVC with VS2017, I have set the Build Action of Index.cshtml
to Content
but still got error.
最后我想页面有问题,所以我复制了Index.cshtml
的内容,删除了Index.cshtml
,然后重新启动Visual Studio.然后我Right click on the Folder > Add > View > Give the file name Index
,在添加了新的空白页之后,粘贴复制的内容,然后再次运行,问题就解决了.
Finally I guess there's something wrong in the page, so I copy the content of Index.cshtml
, delete Index.cshtml
and restart Visual Studio. Then I Right click on the Folder > Add > View > Give the file name Index
, after adding the new empty page, paste the copied content, and run again, the problem is solved.
这篇关于.Net Core 2.0找不到视图“索引"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!