AspNetCore.Docs/aspnetcore/includes/mvc-intro/adding_view1.md

1.0 KiB

Adding a view

By Rick Anderson

In this section you're going to modify the HelloWorldController class to use Razor view template files to cleanly encapsulate the process of generating HTML responses to a client.

You'll create a view template file using Razor. Razor-based view templates have a .cshtml file extension. They provide an elegant way to create HTML output using C#.

Currently the Index method returns a string with a message that is hard-coded in the controller class. In the HelloWorldController class, replace the Index method with the following code:

[!code-csharpMain]

The Index method above returns a View object. It uses a view template to generate an HTML response to the browser. Controller methods (also known as action methods) such as the Index method above, generally return an IActionResult (or a class derived from ActionResult), not primitive types like string.