ASP.NET Core MVC Interview Question #41

What is a ViewResult?

Controllers, Actions, Model Binding & Action Results Junior Beginner

Quick Interview Answer

ViewResult is an IActionResult that renders a Razor view. Controller.View() creates a ViewResult and can optionally specify a view name and model.

Detailed Explanation

ViewResult is an IActionResult that renders a Razor view. Controller.View() creates a ViewResult and can optionally specify a view name and model.

MVC locates the view using its view-location conventions unless an explicit view path or name is provided.

Code Example

public IActionResult Details(int id)
{
    var model = new ProductDetailsViewModel();
    return View(model);
}