DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Deploy an ASP.NET Core Application in the IBM Cloud Code Engine
  • Server-Side Pagination Using ASP.NET Core and Angular 8 - Part Three
  • GDPR Compliance With .NET: Securing Data the Right Way
  • How to Enhance the Performance of .NET Core Applications for Large Responses

Trending

  • How to Format Articles for DZone
  • Unlocking the Benefits of a Private API in AWS API Gateway
  • Docker Base Images Demystified: A Practical Guide
  • The Modern Data Stack Is Overrated — Here’s What Works
  1. DZone
  2. Coding
  3. Frameworks
  4. Getting Started With ASP.NET Core MVC Apps Using VS Code

Getting Started With ASP.NET Core MVC Apps Using VS Code

Hello world! By the end of this tutorial, you'll be able to get that message to print out using ASP.NET Core, C#, and Visual Studio Code.

By 
Santhakumar Munuswamy user avatar
Santhakumar Munuswamy
·
Oct. 08, 17 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
61.4K Views

Join the DZone community and get the full member experience.

Join For Free

In this article, we will discuss how we can create a HelloWorld app with ASP.NET Core 2.0 using Visual Studio Code. We will learn how to create an ASP.NET Core MVC application, how to create a new Controller, how to create a new View, and how to run the HelloWorld app, etc.

Prerequisites

  • .NET Core 2.0 SDK
  • Visual Studio Code
  • VS Code C# extension

If you want to know how to install the new Visual Studio Code in the machine, you can see the easy steps of installation of Visual Studio Code article. Read it here:

  • Getting Started with Visual Studio Code

How to Create an ASP.NET Core MVC Application

Open Visual Studio Code. Now you can open the terminal using the Ctrl+` keyboard shortcut as shown in the screenshot below:

Image title

Now, you can set the project storing location as shown in the screenshot below:

Image title

Type mkdir SampleMVCApps and Enter on the command line.

Image title

Type cd SampleMVCApps and Enter in the command line.

Image title

Type dotnet new MVC and Enter on the command line.

Image title

Go to the Explorer window and Open the SampleMVCApps folder in Visual Studio Code.

Image title

Select Yes to the Warn message "Required assets to build and debug are missing from 'SampleMVCApps.' Add them?"

Image title

Now, you can see the project folder structure as shown in the screenshot below.

Image title

Pressing the F5 button to run the application.

Image title

How to Create a New Controller

Go to the Explorer window in VS Code. Right-click the Controllers folder and the select New File.

Image title

Now, you can type in the controller name, HelloWorldController.cs, and press the Enter button.

Image title

Copy and paste the below code into HelloWorldController.cs

using Microsoft.AspNetCore.Mvc;

namespace SampleMVCApps.Controllers
{
    public class HelloWorldController:Controller
    {
        public IActionResult Index()
        {   
            ViewData["Message"]="Hello, This is my view";
            return View();
        }

        public IActionResult Welcome()
        {
            ViewData["Message"]="Hello, Welcome to HelloWorld Application";
            return View();
        }
    }
}

How to Create a New View

Go to the Explorer window in VS Code. Right-click the Views folder and select New Folder. Then add the new folder named HelloWorld.

Image title

Right-click the HelloWorld folder and point to New File, followed by clicking the New File.

Image title

Now, you can type in the view name, Index.cshtml, and press Enter.

Image title

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

@{
    ViewData["Title"]="Index";
}

<h2>Index</h2>
<hr>

<p>@ViewData["Welcome"]</p>

Similarly, you can create a welcome view. Copy and paste the below code into Views/HelloWorld/Welcome.cshtml

@{
    ViewData["Title"]="Welcome";
}

<h2>Welcome</h2>
<hr>

<p>@ViewData["HelloWorld"]</p>

How to Run the HelloWorld App

Pressing the F5 button will run the application, as shown in the below screenshots:

Image title

Image title

Conclusion

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.



If you enjoyed this article and want to learn more about ASP.NET, check out this collection of tutorials and articles on all things ASP.NET.

ASP.NET Visual Studio Code Virtual screening code style ASP.NET Core app

Published at DZone with permission of Santhakumar Munuswamy. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Deploy an ASP.NET Core Application in the IBM Cloud Code Engine
  • Server-Side Pagination Using ASP.NET Core and Angular 8 - Part Three
  • GDPR Compliance With .NET: Securing Data the Right Way
  • How to Enhance the Performance of .NET Core Applications for Large Responses

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!