Getting Started with ASP.NET Core 1.1 using Visual Studio 2017 on Windows

by Santhakumar Munuswamy

  Posted on  19 March 2017

  ASP.NET Core


 

In this article, we will discuss how we can create a HelloWorld App using Asp.Net Core 1.1 and Visual Studio 2017 in Windows. We will learn how to create an Asp.Net Core Web application project, How to add new Controller, How to add new View, and How to run the HelloWorld App etc. 

In this article, we will see the following

  • How to create an ASP.Net Core Web Application
  • How to add new Controller
  • How to add new View
  • How to run the HelloWorld App

Prerequisite

  • Visual Studio Community 2017
  • .NET Core 1.1 

If you want to know how to install the new Visual Studio 2017 in the machine. You don’t worry about it. You can see the easy steps to installation of Visual Studio 2017 article read it as follows

How to create an ASP.Net Core Web Application

Open Visual Studio 2017. Go to File menu, point to new and click new project. 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) and type Project Name AspNetCoreHelloWorldApp. Choose the project location path and click OK button.


The New Asp.NET Core Web Application (.NET Core) - AspNetCoreHelloWorldApp window will open and Select an Asp.Net Core version 1.1 in the Dropdown box. Select a template as Web Application and keep the default No Authentication. Then, Click OK button.


Now, you can see AspNetCoreHelloWorldApp project structure, as shown in the screenshot, given below



Now, we can run the app with/ without debug mode. If you want to run the app in debug mode. 

Pressing the F5 button to run the app in debug mode. Otherwise, you can go to debug menu item in Visual Studio. Then, click the Start Debugging sub menu item. 


Now, successfully launched the app in the browser



If you want to run the app in non-debug mode. Pressing Ctrl+F5 button to run the app in non-debug mode. Otherwise, you can go to debug menu item in Visual Studio. Then, click the Start Without Debugging sub menu item.


Now, successfully launched the app in the browser



How to add new Controller

In Solution Explorer, Go to the Controllers folder, right-click the Controllers folder and point to Add, followed by clicking the New Item.


You can select an MVC Controller class and type the class name as HelloWorldController and click the Add button.


Copy and past the below code into HelloWorldController.cs

using Microsoft.AspNetCore.Mvc;

// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace AspNetCoreHelloWorldApp.Controllers

{

    public class HelloWorldController : Controller

    {

        // GET: /<controller>/

        public IActionResult Index()

        {

            ViewBag.Title = "Index";

            ViewBag.Message = "Hello World";

            return View();

        }

    }

}

Now, you can change the controller name as shown in the below screenshot



How to add new View

In Solution Explorer, Go to the Views folder, right-click the views folder and point to Add, followed by clicking the New Folder. Then, the name of the folder HelloWorld.

In Views folder, Go to the HelloWorld folder, right-click the HelloWorld folder and point to Add, followed by clicking the New Item.


You can select an MVC View page and type file name as Index and click Add button.


Copy and paste the below code into Views/HelloWorld/Index.cshtml 

@*

    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

*@

@{

    ViewData["Title"] = @ViewBag.Title;

}

<h2>@ViewBag.Title</h2>

<p>@ViewBag.Message</p>


How to run the HelloWorld App

Pressing the F5 or CTRL + F5 button to run the app in debug mode or non-debug mode as shown in the below screenshot



Conclusion

I hope you understood how to create a HelloWorld App using Asp.Net Core 1.1 and Visual Studio 2017, How to add new Controller, How to add the new view and How to run the HellowWorld App. I have covered all the required things. If you found anything which I missed in this article, Please let me know. Please share your valuable feedback or comments and suggestion to improve the future articles.

 


About the Author
Santhakumar Munuswamy is a seasoned Solution Architect and Most Valuable Professional in Cloud /AI solutions. He has been experienced around 14 years in Solution designing, Software Product Development, Technical Documentation, Project Management for Web and Cloud Applications. He has experience in the IT industry across different domains (Automotive, Telecommunications, Healthcare, Logistics & Warehouse Automation, etc.) with roles in Technical Architect, Genesys Consultant, Technical Lead, Team Lead, and Developer. He has experienced in mentorship and coaching high potential developers.

Follow Me: Facebook, Twitter, Google Plus, LinkedIn
blog comments powered by Disqus


Month List

Community Badges