❔ View cannot be found.
LoginModel.cs
Pages/Account/Login.cshtml
Pages/Account/Register.cshtml
AccountController.cs attached.
Why am I getting the following error when submitting a POST request?
11 Replies
Why do you have your views in
/Pages/
instead of /Views/
directory...?
The exception is quite clear, it tells you what directories it searches through to find the appropriate viewHey, so /Pages/ was the default folder added by the scaffolding. I tried creating a /Views/ folder and moving the relevant files there but I ran into some 405 issues so I assumed /Pages/ was the correct way.
I can't quite puzzle it together.
If it was scaffolded code, that means what got scaffolded were some Razor Pages
So either:
a) Use them as they are
b) Use controllers and views
Trying to mix the two won't work
So /Pages/ is not a synonym for /Views/ then? Because that's what I got when creating the project ("scaffolding"(?)).
For example, there is a "/Pages/Shared/" which was searched, and even though I tried putting the "Login.cshtml" and "Register.cshtml" there it did not find them.
The MVC paradigm uses
/Controllers/
for controllers and /Views/
for views. The Razor Pages paradigm uses /Pages/
for... pages
If you want to use MVC, it's best to place your views where views go, and controllers where controllers go
If you want to use Razor Pages, place them where they goI did not realize these were different frameworks.
But it seems like using controllers and .cshtml files with the "@page" directive works? Because that's how I got it to work partially during my work on this.
You would recommend me to troubleshoot this on google by using "MVC" as part of the keyword(s) searched?
I would recommend starting with placing things where they should go
Or using the scaffolded Razor Pages code for auth, and not making your own implementation of it with MVC
That would be the easiest
I am on the final stretches of my C# programming course and I guess MVC was what we learned. I don't know how I got Razor pages in the mix, but I think MVC is the way to go for me.
But let's suppose I did want to do the Razor Pages code way, isn't it essentially just moving the code in there?
I am using Aspnet.core.Identity and entityframeworkcore for Auth and DB respectively.
Identity will scaffold Razor Pages with login, registration, etc for you
Once scaffolded, that's that, you don't need to touch them
Or you can edit the codebehind in them if you want
But trying to replace them with controllers, while still using the pages'
.cshtml
files is... an odd choiceOh really, I must have navigated around that somehow. I installed it through the NuGet package manager and no code was provided by default.
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.