Start United States USA — software Create a Minimal ASP. NET Core 2.0 MVC Web Application

Create a Minimal ASP. NET Core 2.0 MVC Web Application

304
0
TEILEN

A web developer shows us how to create an ASP. NET Core 2.0 MVC application from scratch, starting off with a blank template and filling it with C# and CSHTML.
This guide shows you how to set up an ASP. NET Core 2.0 MVC web application from an empty template.
You can create a project using the MVC template in. NET Core but it will often include a load of things that we don’t need. My preference is always to start a project from scratch.
Here are the steps to go from an empty project to an MVC ready project.
You will need to install the following:
First, create a new ASP. NET Core Web Application and choose the empty template, making sure you are targeting ASP. NET Core 2.0.
The empty project contains little more than wwwroot, Program.cs and Startup.cs. It may seem a little unusual that Program.cs is in there but web apps are now, essentially, console applications and contain a Program.cs just the same as a console app would. This means web apps can now be run from the command line.
The default code in Startup.cs contains:
This writes „Hello World!“ in the response stream. Press F5 and you should see the result in the browser.
Now install MVC via NuGet Package Manager:
Once installed, there are a couple of things we’ll need to add to Startup.cs. Firstly, configure the app to use the MVC framework.
Secondly, configure the app to use the MVC request execution pipeline (routing) , with a default route.
Now that the MVC framework has been added, let’s add a Controller and a View!
This adds scaffolding to the project and now the MVC templates for Controllers and Views will work. When it has finished, right click and add a Controller again.
Add a little HTML into Index.cshtml
And then run the app, it should show in the browser, like so:
And we’re done!
Setting up a project from an empty template is always my preferred approach and as you can see it is very simple and quick to set up an MVC app using ASP. NET Core 2.0. Give it a try!

Continue reading...