AspNetCore.Docs/aspnetcore/tutorials/first-mvc-app/adding-controller.md

36 lines
1.1 KiB
Markdown
Raw Normal View History

2016-10-29 01:35:15 +08:00
---
title: Add a controller to an ASP.NET Core MVC app
2018-01-29 23:21:31 +08:00
author: rick-anderson
description: Learn how to add a controller to a simple ASP.NET Core MVC app.
2016-10-29 01:35:15 +08:00
manager: wpickett
2018-01-29 23:21:31 +08:00
ms.author: riande
ms.date: 02/28/2017
ms.prod: asp.net-core
2018-01-29 23:21:31 +08:00
ms.technology: aspnet
ms.topic: get-started-article
2016-10-29 01:35:15 +08:00
uid: tutorials/first-mvc-app/adding-controller
---
# Add a controller to an ASP.NET Core MVC app
2016-10-29 01:35:15 +08:00
By [Rick Anderson](https://twitter.com/RickAndMSFT)
2016-10-29 01:35:15 +08:00
2018-04-05 07:51:35 +08:00
[!INCLUDE [adding-controller1](../../includes/mvc-intro/adding-controller1.md)]
2016-10-29 01:35:15 +08:00
* In **Solution Explorer**, right-click **Controllers > Add > New Item**
2016-10-29 01:35:15 +08:00
![Contextual menu](adding-controller/_static/add_controller.png)
2016-10-29 01:35:15 +08:00
* Select **Controller Class**
2016-10-29 01:35:15 +08:00
* In the **Add New Item** dialog, enter **HelloWorldController**.
![Add MVC controller and name it](adding-controller/_static/ac.png)
2018-04-05 07:51:35 +08:00
[!INCLUDE [adding-controller2](../../includes/mvc-intro/adding-controller2.md)]
2016-10-29 01:35:15 +08:00
In Visual Studio, in non-debug mode (Ctrl+F5), you don't need to build the app after changing code. Just save the file, refresh your browser and you can see the changes.
2016-10-29 01:35:15 +08:00
2018-04-05 07:51:35 +08:00
> [!div class="step-by-step"]
> [Previous](start-mvc.md)
> [Next](adding-view.md)