Tech Junkie Blog - Real World Tutorials, Happy Coding!: Hour 3: Enable MVC On ASP.NET Core Application

Thursday, July 25, 2019

Hour 3: Enable MVC On ASP.NET Core Application

In this post we will go over the process of enabling ASP.NET MVC in our application.  Just like static files, in order for us to use MVC in our application we have to tell ASP.NET Core to use Mvc in the Startup.cs file.  We will continue to use the application "NorthwindCafe" that we used in our previous blog.

Here are the steps to add MVC to your application:

1.  Open the Startup.cs file, then in "Configure" method type in the following to enable MVC

       
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseStaticFiles();
            app.UseMvc();
        }


The app.UseMvc method tells the application to use ASP.NET Core MVC framework for this application


Even though we have enabled MVC in our application we haven't configure any routes for it.  We will do that in the next post.

github Repositoryhttps://github.com/techjunkiejh/NorthwindCafe/tree/Hour3

2 comments:

Search This Blog