In this article we are going to explain how to create mvc .net core 2.0 application and add view using in visual studio 2017 with example.
How to create an MVC ASP.Net Core Web Application and add view
Open Visual Studio 2017. Go to File menu, point to new and click New project or click create new project link button on directly start page.
The "New Project" window will open. You can select an installed template like “.NET Core” in Visual C# Template and then select the Asp.Net Core Web Application (.NET Core). Type project name, such as - MvcCore. Choose the project location path and click OK button.
The New ASP.NET Core Web Application (.NET Core) - MvcCore window will open. Select ASP.NET Core version 2.0 in the dropdown box. Select a template as Web Application (Model-View-Controller) and Then, click the OK button.
Now, you can see MvcCore project structure, as shown in the screenshot given below.
In Solution Explorer, go to the Controllers folder, right click it and point to Add, followed by clicking the New Item.
Now open a popup window, select controller template and click add button.
Now open (Add MVC Controller) popup window, enter controller Name and click add button.
Copy and paste the below code in UserController.cs.
public class UserController: Controller
public IActionResult Index()
ViewBag.Title = "Index";
ViewBag.Message= "User Page";
In Solution Explorer, go to the Views folder, right-click it and point to Add, followed by clicking the New Folder. Then, name the folder as User.
Again, in Views folder, go to the User folder, right-click it and point to Add, and click to view.
Now open (Add MVC View ) popup window, Enter view name as Index, and click Add button.
Copy and paste the below code into Views/User/Index.cshtml.
Pressing the F5 or CTRL + F5 button will run the app in debug mode, as shown in the below screenshot.
I hope you understand now how to create a controller in asp.net mvc App using .Net Core 2.0 and Visual Studio 2017.
Please share your valuable feedback or comments to improve my future articles.