Rutger
Rutger

Reputation: 21

Razor pages without .cshtml file? Getting a System.InvalidOperationException: The view 'Login' was not found

I'm currently working on a project with an older .Net Core 2.2 webapi which has to be updated to a more recent version. All the developers who has worked on this project has left this company a pretty long time ago, so I have to figure out myself how everything should be configured and how the components are connected to each other.

Beside the WebApi solution there is also an Identity provider build around IdentityServer4. And for the different views for the Controllers there are some Razor pages without a corresponding .cshtml file. I'm pretty confident with Razor pages, however a solution with Razor pages without .cshtml is new for me.

When I try to do an api call with Postman, all I get is an InvalidOperationException because the view can't be find: The view Login was not found image

System.InvalidOperationException: The view 'Login' was not found. The following locations were searched:
/Views/Account/Login.cshtml
/Views/Shared/Login.cshtml
/Pages/Shared/Login.cshtml
  at Microsoft.AspNetCore.Mvc.ViewEngines.ViewEngineResult.EnsureSuccessful(IEnumerable`1 originalLocations)
  at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor.ExecuteAsync(ActionContext context, ViewResult result)

The folder structure of the inline Razor files is looking like: Folder structure

And the content of the file which corresponds with the Login view: Inline login view

[RazorInject]
public IModelExpressionProvider ModelExpressionProvider { get; private set; }

[RazorInject]
public IUrlHelper Url { get; private set; }

[RazorInject]
public IViewComponentHelper Component { get; private set; }

[RazorInject]
public IJsonHelper Json { get; private set; }

[RazorInject]
public IHtmlHelper<LoginViewModel> Html { get; private set; }

public override async Task ExecuteAsync()
{
    BeginContext(22, 95, isLiteral: true);
    WriteLiteral("<div class=\"test browser\">\n    <div class=\"logo\"></div>\n    <div class=\"input-fields\">\n        ");
    EndContext();

So basically, I can read the structure of a normal .cshtml view file in it, but now in .cs code. I already tried changing the resource kind and build Action of the file without any difference so far, it can't find the View.

I'm pretty sure that there isn't supposed to be a View folder directory structure, as this code should be working, so what am I missing here?

Upvotes: 0

Views: 124

Answers (0)

Related Questions