Return view from action method in ASP.NET MVC

How to return a view from controller action method?

To return a view from the controller action method, we can use View() method by passing respective parameters.
ACTION METHOD CODE
public ViewResult OutputView()
  {
      return View();
  }
  • return View() – returns the view corresponding to the action method
  • return View(“ViewName”) – returns the view name specified in the current view folder (view extension name “.cshtml” is not required.
  • return View("~/Views/Account/Register.cshtml") – returns the Register view under /Views/Account folder (view extension name “.cshtml” is required as we are passing the complete path name of the view that exists in another folder).

No comments:

Post a Comment

How to register multiple implementations of the same interface in Asp.Net Core?

 Problem: I have services that are derived from the same interface. public interface IService { } public class ServiceA : IService { ...