A `ViewResult` tells ASP.NET Core MVC to render a view instead of returning a plain string. A controller action creates one by calling `View`, optionally supplying a view model for the view to use when generating HTML. section 2.3.3 section 2.3.4
Listing 2.7 Rendering a view in the HomeController.cs file in the Controllers folder
using Microsoft.AspNetCore.Mvc;
namespace FirstProject.Controllers {
public class HomeController : Controller {
public ViewResult Index() {
return View("MyView");
}
}
}
`HomeController.Index` returns `View("MyView")`, selecting the named view for the response. section 2.3.3
For that action, place `MyView.cshtml` in `Views/Home`. If the file is missing, a request to `http://localhost:5000` produces an error showing where ASP.NET Core looked. Controller-specific views live under `Views/<ControllerName>`; `Views/Shared` holds views not specific to one controller. section 2.3.3
Listing 2.9 Using a view model in the HomeController.cs file in the Controllers folder
using Microsoft.AspNetCore.Mvc;
namespace FirstProject.Controllers {
public class HomeController : Controller {
public ViewResult Index() {
int hour = DateTime.Now.Hour;
string viewModel =
hour < 12 ? "Good Morning" : "Good Afternoon";
return View("MyView", viewModel);
}
}
}
The action chooses a greeting from the current hour and passes it as the second argument to `View("MyView", viewModel)`. The corresponding Razor view declares `@model string` and inserts the value with `@Model`. section 2.3.3
Thank a form respondent
After an RSVP form is submitted, `RsvpForm` returns a `ViewResult` selecting `Thanks` and passing the model-bound `GuestResponse`. In `Views/Home/Thanks.cshtml`, `@Model?.Name` addresses the guest, while `WillAttend` determines which message appears. section 3.2.7
The request path is straightforward: routing selects an action; the action returns a `ViewResult` containing a view name and model; the Razor view engine locates and processes the view; the resulting response goes to the browser. section 2.3.4

