C
C#13mo ago
OkOk

❔ What makes two Controllers work differently?

I am not able to take the controller of one tutorial and apply it to the sample-project of another tutorial. Both from Microsoft. What is it that makes this "Welcome" function break the project? What is it that makes these two projects controllers seemingly work differently from each other?
32 Replies
OkOk
OkOk13mo ago
OkOk
OkOk13mo ago
Both these code snippets are found from the beginners tutorial on MVC
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
OkOk
OkOk13mo ago
Okey so plain html is an example of a primitive Inheriting from ControllerBase and Controller are two completely different things Not that I understand which I should start using
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
OkOk
OkOk13mo ago
One of them uses "[HttpGet]" the other does not
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
OkOk
OkOk13mo ago
I understand
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
OkOk
OkOk13mo ago
You are saying don't use "[HttpGet]"
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
OkOk
OkOk13mo ago
I'm guessing "[ApiController]" should only be used for APIs. But I also wan't to incorporate Razor pages into this project
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
OkOk
OkOk13mo ago
I understand that the name of the function creates the path I meant I want this mvc-project to create html-pages using razor
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
OkOk
OkOk13mo ago
Yes I accidentally used a word "Razor pages" when I was not refering to that specific thing So if I have this api project It's using [ApiController] and it has "ControllerBase" Now I want it to use Razor
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
OkOk
OkOk13mo ago
I assumed I could just add some more controllers like this welcome function that would direct to a view
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
OkOk
OkOk13mo ago
I am a junior developer and i'm trying to keep up
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
OkOk
OkOk13mo ago
Is this a name "AddControllerAndView" ? Can't find it
MODiX
MODiX13mo ago
TeBeCo
i suggest you create ELSEWHERE a separated dotnet new mvc -n JustToLookAtIt
React with ❌ to remove this embed.
OkOk
OkOk13mo ago
Yes I am forced to learn MVC I thought I would try making projects during summer break
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
OkOk
OkOk13mo ago
This project itself is not vital as you can see
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
OkOk
OkOk13mo ago
I made another project to compare as you said
OkOk
OkOk13mo ago
I thought I should perhaps make another controller that inherits Controller instead I could see what "AddControllerAndView" was, and added it to the old project Why does it seem to think all these things already exist? Is this what you meant? It seems like errors arose from the solution
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
OkOk
OkOk13mo ago
I made your solution work Thank you so much @TeBeClone
Accord
Accord12mo ago
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.