📜  Json Action 可以返回视图吗? - C# 代码示例

📅  最后修改于: 2022-03-11 14:48:53.737000             🧑  作者: Mango

代码示例1
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();
     }
}