Answers for "can a Json Action return a view?"

C#
0

can a Json Action return a view?

protected string RenderPartialViewToString(string viewName, object model)
{
     controller.ViewData.Model = model;

     using (StringWriter sw = new StringWriter())
     {
          ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(controller.ControllerContext, viewName);
          ViewContext viewContext = new ViewContext(controller.ControllerContext, viewResult.View, controller.ViewData, controller.TempData, sw);
          viewResult.View.Render(viewContext, sw);

          return sw.GetStringBuilder().ToString();
     }
}
Posted by: Guest on July-29-2020

Code answers related to "can a Json Action return a view?"

C# Answers by Framework

Browse Popular Code Answers by Language