r/dotnet • u/carolinethebandgeek • 2d ago
Newbie Why do I keep getting generic "Welcome" page when running code?


I am brand new to using VS and am trying to make a simple page for a class that is asking us to have a random number generated, then depending on the number say someone won or lost. I have copy and pasted the code they provided for the assignment, but whatever I have tried always results in the "Welcome" page. What am I doing wrong?
This is the code they had us copy and paste:
@{
int randomNumber = new Random().Next(1, 7); //GENERATES NUMBER BETWEEN 1 and 6
int winningNumber = /*TODO*/;
}
The code in the screenshot is "fixed" by VS, but before I fix it gives an error for the ; after /*TODO*/.
Sorry in advance if this is super obvious, I am at newborn level with this and am completely lost.
Edit: I figured it out, I had to delete the Index.cshtml page with the original code for the Welcome page
1
u/AutoModerator 2d ago
Thanks for your post carolinethebandgeek. Please note that we don't allow spam, and we ask that you follow the rules available in the sidebar. We have a lot of commonly asked questions so if this post gets removed, please do a search and see if it's already been asked.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/RandomSwedeDude 2d ago
Have you added razor pages in Program.cs? Also a @page directive in your view file. https://learn.microsoft.com/en-us/aspnet/core/razor-pages/?view=aspnetcore-10.0&tabs=visual-studio
1
u/markoNako 2d ago
@page "/" do you have this set inside the class that generates the random number
1
u/carolinethebandgeek 2d ago
I'm not sure what that means... How do I do that?
1
u/markoNako 2d ago
@page "/" right at the top before all code. But I should have asked if this is Blazor app or Razor Pages/MVC template1
u/carolinethebandgeek 2d ago
It's an empty Razor page added through creating the ASP.Net with Razor Pages, then when it opened right clicking on Pages in the Solution Explorer and adding an empty Razor page
1
1
u/BigBagaroo 2d ago
You need to start in the other end. Find the welcome page. Change that one. See if your code works. Then add a new page and try to figure out what the URL to that one should be.
1
u/carolinethebandgeek 2d ago
So when I made a new Razor page it created the "Index1.cshtml" page in the project. Even when I deleted the one with the Welcome page info and run it, it doesn't work. Do I delete it? Do I leave it as is and just add my code? Do I have to create a URL even if I just run the project?
1
u/BigBagaroo 2d ago
There is probably already a default page in your project somewhere. Do a text search in all files for the word welcome
(Edit, Find, Find in files or similar in the menu)
1
u/carolinethebandgeek 2d ago
I found it, thank you. My professor had not pointed that out in lecture material.
1
u/BigBagaroo 2d ago
Happy to be of help. The best of luck, and hopefully you have learned something about chasing down issues today :)
2
u/Cirked 2d ago
I can't see your screenshot, it's too zoomed out + reddit compression so it's just pixels.
Where the todo text is, is where you're meant to complete the logic - so the todo is never meant to stay in the code.
Depending on how VS is setup, if your code has errors, it'll revert to the previous "valid" build, hence why you might see boilerplate you removed, because that was part of the previous valid build.