Returning a partial view from controller action method in ASP.NET MVC

How to return a partial view from controller action method?

To return a Partial view from the controller action method, we can write return type as PartialViewResult and return using PartialView method.
public PartialViewResult OutputPartialView()
  {
      return PartialView("_GetFileName"); // returns view with model
  }
In the above code, we are assuming that _GetFileName.cshtml exists in the controller specific folder otherwise we need to specify the complete file name of the view from the root of the application (like "~/Views/PersonalDetails/_ViewName").

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 { ...