Resolved How can we run a view/application in MVC?

Anonymous

Well-known member
Joined
Sep 29, 2020
Messages
84
Programming Experience
Beginner
Hello, I am trying to learn MVC. I first created an empty ASP.NET Core application. Then, I added a Controller.

C#:
namespace website.Controllers
{
    public class HomeController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }
    }
}


I then added a simple view by right clicking View() - Home.cshtml

C#:
<h1>Hello! Welcome to the Home Page!</h1>

But when I run the code, it shows me Hello World!, which is present in the Startup.cs page.

C#:
app.UseEndpoints(endpoints =>
            {
                endpoints.MapGet("/", async context =>
                {
                    await context.Response.WriteAsync("Hello World!");
                });
            });


When I used the following path -


This localhost page can’t be found​


This is how I have placed my files -

1656425709286.png




I am sorry for asking a basic question. I am not able to figure this out. I have used webforms before and they used to run whenever I clicked IIS Express in Visual Studio.
 
How exactly did you create your project? It looks like you chose the "ASP.NET Core Empty" project template. You should have chosen the "ASP.NET Core Web App (Model-View-Controller)" instead.

The former assumes that you know all the guts underneath ASP.NET Core and you will build things up yourself.
 
Back
Top Bottom