C
C#2y 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
OkOkOP2y ago
OkOk
OkOkOP2y ago
Both these code snippets are found from the beginners tutorial on MVC
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
OkOk
OkOkOP2y 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 User2y ago
Message Not Public
Sign In & Join Server To View
OkOk
OkOkOP2y ago
One of them uses "[HttpGet]" the other does not
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
OkOk
OkOkOP2y ago
I understand
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
OkOk
OkOkOP2y ago
You are saying don't use "[HttpGet]"
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
OkOk
OkOkOP2y 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 User2y ago
Message Not Public
Sign In & Join Server To View
OkOk
OkOkOP2y 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 User2y ago
Message Not Public
Sign In & Join Server To View
OkOk
OkOkOP2y 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 User2y ago
Message Not Public
Sign In & Join Server To View
OkOk
OkOkOP2y ago
I assumed I could just add some more controllers like this welcome function that would direct to a view
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
OkOk
OkOkOP2y ago
I am a junior developer and i'm trying to keep up
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
OkOk
OkOkOP2y ago
Is this a name "AddControllerAndView" ? Can't find it
MODiX
MODiX2y ago
TeBeCo
i suggest you create ELSEWHERE a separated dotnet new mvc -n JustToLookAtIt
React with ❌ to remove this embed.
OkOk
OkOkOP2y ago
Yes I am forced to learn MVC I thought I would try making projects during summer break
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
OkOk
OkOkOP2y ago
This project itself is not vital as you can see
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
OkOk
OkOkOP2y ago
I made another project to compare as you said
OkOk
OkOkOP2y 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 User2y ago
Message Not Public
Sign In & Join Server To View
OkOk
OkOkOP2y ago
I made your solution work Thank you so much @TeBeClone
Accord
Accord17mo 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.
Want results from more Discord servers?
Add your server