Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The view 'Index' was not found #25157

Closed
nferobot opened this issue Feb 28, 2022 · 23 comments
Closed

The view 'Index' was not found #25157

nferobot opened this issue Feb 28, 2022 · 23 comments
Labels
Source - Docs.ms Docs Customer feedback via GitHub Issue ⌚ Not Triaged

Comments

@nferobot
Copy link

nferobot commented Feb 28, 2022

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.

@dotnet-bot dotnet-bot added ⌚ Not Triaged Source - Docs.ms Docs Customer feedback via GitHub Issue labels Feb 28, 2022
@Rick-Anderson
Copy link
Contributor

That's a really good error message.

@umityeke
Copy link

umityeke commented Mar 5, 2022

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

@Rick-Anderson
Copy link
Contributor

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

Really good error message.

@umityeke
Copy link

umityeke commented Mar 6, 2022

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

@Rick-Anderson
Copy link
Contributor

So what did you do wrong?

i solved cmd - dotnet watch run :)

@umityeke
Copy link

umityeke commented Mar 6, 2022

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

@vipin14904
Copy link

Without command how we can run project vai IIS express?

@Sergio1C
Copy link

Sergio1C commented Jun 11, 2022

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.

@nammadhu
Copy link

nammadhu commented Jul 8, 2022

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

@camerontbelt
Copy link

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

@lalibi
Copy link

lalibi commented Aug 1, 2022

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.

@Sergio1C
Copy link

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.

@pravinkamane
Copy link

pravinkamane commented Nov 1, 2022

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"

@Yondo-r
Copy link

Yondo-r commented Mar 7, 2023

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

@rtavassoli
Copy link

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

@Yearmix
Copy link

Yearmix commented Sep 14, 2023

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

@axepertpt
Copy link

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

@lDevDes
Copy link

lDevDes commented Nov 14, 2023

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?

@InnerCat
Copy link

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.

@pedrovazfontes
Copy link

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

Thanks, this resolved my case

@Mamun49
Copy link

Mamun49 commented Feb 6, 2024

builder.Services.AddControllersWithViews().AddRazorRuntimeCompilation();

This one work for me.

@skironDotNet
Copy link

I just noticed when create a fresh project on VS 2022 17.8.7 I get that error,
when I go to project dir, and run dotnet run the app works fine

@douglasg14b
Copy link

douglasg14b commented Jul 13, 2024

Yeah this is driving me up a wall....

Actually ran out of google results. And it sounds like AddRazorRuntimeCompilation() is the "not recommended" way to do this? What is the right way?

image
image
image

Adding AddRazorRuntimeCompilation() gets past the "not found" error, and rops into a whole new hell of:

Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.CompilationFailedException: One or more compilation failures occurred:
mtcglgj3.3l0(4,20): error CS0400: The type or namespace name 'Microsoft' could not be found in the global namespace (are you missing an assembly reference?)
mtcglgj3.3l0(4,82): error CS0518: Predefined type 'System.Type' is not defined or imported
mtcglgj3.3l0(4,134): error CS0518: Predefined type 'System.String' is not defined or imported
mtcglgj3.3l0(4,151): error CS0518: Predefined type 'System.String' is not defined or imported
mtcglgj3.3l0(8,11): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
...

As far as I can tell, and I've now visited nearly 47 different threads looking for answers, MVZ views just "don't work". Which doesn't seem likely, given they do actually work in example projects. But adding them to an existing project appears to be a nightmare straight out of the 5th layer of hell where where also find CakePHP, ASPNET webforms, and Coffeescript being buddy-buddy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Source - Docs.ms Docs Customer feedback via GitHub Issue ⌚ Not Triaged
Projects
None yet
Development

No branches or pull requests