AspNetCore.Docs icon indicating copy to clipboard operation
AspNetCore.Docs copied to clipboard

The view 'Index' was not found

Open nferobot opened this issue 4 years ago • 23 comments

Visual Studio Community 2019 for Mac Version 8.10.19 (build 2)

1- create project Web application MVC (net 5.0) 2- upgrade to Net 6.0 (https://docs.microsoft.com/en-us/aspnet/core/migration/50-to-60?view=aspnetcore-6.0&tabs=visual-studio-mac) 3 - run 4 - Exception Error : fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1] An unhandled exception has occurred while executing the request. System.InvalidOperationException: The view 'Index' was not found. The following locations were searched: /Views/Home/Index.cshtml /Views/Shared/Index.cshtml

API Working fine , Web application MVC not working

Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

nferobot avatar Feb 28 '22 07:02 nferobot

That's a really good error message.

Rick-Anderson avatar Feb 28 '22 17:02 Rick-Anderson

InvalidOperationException: The view 'Index' was not found. The following locations were searched: /Views/Home/Index.cshtml /Views/Shared/Index.cshtml

umityeke avatar Mar 05 '22 17:03 umityeke

InvalidOperationException: The view 'Index' was not found. The following locations were searched: /Views/Home/Index.cshtml /Views/Shared/Index.cshtml

Really good error message.

Rick-Anderson avatar Mar 05 '22 20:03 Rick-Anderson

i solved cmd - dotnet watch run :) you helped a lot man :) 🗡️

umityeke avatar Mar 06 '22 19:03 umityeke

So what did you do wrong?

i solved cmd - dotnet watch run :)

Rick-Anderson avatar Mar 06 '22 19:03 Rick-Anderson

So I didn't run a dotnet for short.🤣🤣🤣

umityeke avatar Mar 06 '22 20:03 umityeke

Without command how we can run project vai IIS express?

vipin14904 avatar Apr 26 '22 04:04 vipin14904

I have VS 2019 (v. 16.11.2). Just created a new ASP.NET Core Web MVC application (was targeting to net5.0 by default, but I had to specify net6.0 there). After that, I was getting the same error whenever I launched the project via standard "run IIS express". I noticed, the error goes away if I run its via "dotnet run" command. But it must work from IDE as well..So, the issue still exists actually.

dotnet sdk version (via dotnet --info): 6.0.201

P.S I can't update to VS2022 as my laptop too slow for its.

Sergio1C avatar Jun 11 '22 21:06 Sergio1C

i was also facing similar issue,took long time to fix... Solution is in .csproj if any views are with Remove then delete those entry and include those views to project in solution explorer... then actual fix is just add one test view viewfile index3.cstml and make it called from action then deploy all works well. Later can remove that extra view file. 100% it works. https://stackoverflow.com/questions/49483693/net-core-2-0-the-view-index-was-not-found/72907896#72907896

nammadhu avatar Jul 08 '22 07:07 nammadhu

Is there any resolution to this error? I am also seeing this even though it tells me it search exactly where the view is located. An unhandled exception occurred while processing the request. InvalidOperationException: The view 'Index' was not found. The following locations were searched: /Areas/Fluids/Views/WorkOrderRecon/Index.cshtml /Areas/Fluids/Views/Shared/Index.cshtml /Views/Shared/Index.cshtml /Pages/Shared/Index.cshtml

Endpoint

Name Value
Display Name CorporateSite.Web.Controllers.Fluids.WorkOrderReconController.Index (CorporateSite.Web)
Route Pattern Fluids/{controller}/{action=Index}/{id?}
Route Order 1
Route HTTP Method GET

Route Values

Variable Value
action Index
area Fluids
controller WorkOrderRecon

camerontbelt avatar Jul 21 '22 20:07 camerontbelt

I had the same issue because I manually updated my project to .net 6.0 but was still using VS 2019.

At some point, during building, it says that VS 2019 does not support .net 6.0, or something like that.

I had to upgrade to VS 2022.

lalibi avatar Aug 01 '22 19:08 lalibi

I had the same issue because I manually updated my project to .net 6.0 but was still using VS 2019.

At some point, during building, it says that VS 2019 does not support .net 6.0, or something like that.

I had to upgrade to VS 2022.

Is there any workaround in case upgrading to VS2022 is not possible? I was trying to follow a suggestion from @madhusudhan-v (delete existing .cshtml file and create a new one) but it didn't solve this issue.

Sergio1C avatar Oct 27 '22 08:10 Sergio1C

I was facing this issue when I upgraded my .net application to .net core 6.0

<TargetFramework>net6.0</TargetFramework>
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>

this AddRazorSupportForMvc setting helped to resolve this issue of "the-view-index-was-not-found"

pravinkamane avatar Nov 01 '22 07:11 pravinkamane

I had the same problem. Following @pmadusud-v's tip, I looked at my csproject and saw that he had removed and included my view..

`ItemGroup> -- removed Content Remove="Views\Championships\Login.cshtml" /> -- removed /ItemGroup> -- removed

ItemGroup> --lot of packages /ItemGroup>

ItemGroup> -- removed None Include="Views\Championships\Login.cshtml" /> -- removed /ItemGroup> -- removed

I didn't understand why this was put in my csproject, but I removed it and it worked

Yondo-r avatar Mar 07 '23 15:03 Yondo-r

This solved it for me https://www.google.com/search?q=The+view+%27Index%27+was+not+found&oq=The+view+%27Index%27+was+not+found&aqs=chrome..69i57j0i19i512l2j0i19i22i30l7.705j0j4&sourceid=chrome&ie=UTF-8#fpstate=ive&vld=cid:8729b706,vid:oQSOnRqHMHs

rtavassoli avatar Apr 17 '23 12:04 rtavassoli

Have a try adding Nuget <PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="6.0.22" /> and change a line in Program.cs builder.Services.AddControllersWithViews(); to builder.Services.AddControllersWithViews().AddRazorRuntimeCompilation(); I don't deep dive inside but it helps me.

OR add SDK 6-7 and update VS2022

Yearmix avatar Sep 14 '23 12:09 Yearmix

In my case (core 6) AreaViewLocationFormats did not work correctly. Solution: add a controller tag or method [Area("your_area")] to the controller

axepertpt avatar Oct 12 '23 07:10 axepertpt

This works temporarily in development when you publish to a server, it comes back and the exception appears. Have you resolved this from the root?

That is, installing Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation works but when publishing to ISS the error appears again, is there any definitive solution for both development and production, am I using visual 2022?

lDevDes avatar Nov 14 '23 14:11 lDevDes

For me this error apeared suddenly. The project launched successfully, but on the next try, “index not found.” The problem was in one of the views in the razor syntax. In another cshtml, not in the Index. I started construction '@(' but didn't close it correctly with ')'. In this state, the program compiles and runs, but cannot find its views. Check it out, it might be the same for you. In the view with an error, all html tags after the wrong '@(' will not have highlighting.

InnerCat avatar Dec 28 '23 15:12 InnerCat

essa configuração AddRazorSupportForMvc ajudou a resolver esse problema de "the-view-index-was-not-found"

Thanks, this resolved my case

pedrovazfontes avatar Jan 06 '24 22:01 pedrovazfontes