Getting Started With ASP.NET Core 1.1 Using Visual Studio 2017 On Windows

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 can see the easy steps of installation of Visual Studio 2017 article. Read it from here -

How to create an ASP.Net Core Web Application

Open Visual Studio 2017. Go to File menu, point to new and click New project. 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 tghe project namem, such as - AspNetCoreHelloWorldApp. Choose the project location path and click OK button. 



The New ASP.NET Core Web Application (.NET Core) - AspNetCoreHelloWorldApp window will open. Select ASP.NET Core version 1.1 in the dropdown box. Select a template as Web Application and keep the default No Authentication. Then, click the 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 will do the trick. Otherwise, you can go to debug menu item in Visual Studio. Then, click the "Start Debugging" sub menu item.


Now, you have successfully launched the app in the browser.

 

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

 

Now, we have successfully launched the app in the browser

How to add new Controller

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

 

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



Copy and paste the below code in HelloWorldController.cs.
  1. using Microsoft.AspNetCore.Mvc;  
  2.   
  3. // For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860  
  4.   
  5. namespace AspNetCoreHelloWorldApp.Controllers  
  6.   
  7. {  
  8.   
  9.     public class HelloWorldController : Controller  
  10.   
  11.     {  
  12.   
  13.         // GET: /<controller>/  
  14.   
  15.         public IActionResult Index()  
  16.   
  17.         {  
  18.   
  19.             ViewBag.Title = "Index";  
  20.   
  21.             ViewBag.Message = "Hello World";  
  22.   
  23.             return View();  
  24.   
  25.         }  
  26.   
  27.     }  
  28.   
  29. }  

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 it and point to Add, followed by clicking the New Folder. Then, name the folder as HelloWorld.

Again, in Views folder, go to the HelloWorld folder, right-click it and point to Add, followed by clicking the New Item.



Select an MVC View page, type file name as Index, and click Add button.

 

Copy and paste the below code into Views/HelloWorld/Index.cshtml.
  1. Copy and paste the below code into Views/HelloWorld/Index.cshtml   
  2.   
  3. @*  
  4.   
  5.     For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860  
  6.   
  7. *@  
  8.   
  9. @{  
  10.   
  11.     ViewData["Title"] = @ViewBag.Title;  
  12.   
  13. }  
  14.   
  15. <h2>@ViewBag.Title</h2>  
  16.   
  17. <p>@ViewBag.Message</p>  

How to run the HelloWorld App

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

 
Reference

Conclusion

I hope you understand now 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 find anything missing, please let me know.

Please share your valuable feedback or comments to improve my future articles.

X

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now