最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Asp.Net MVC 把PartialView、View转换成字符串
时间:2022-06-25 08:53:09 编辑:袖梨 来源:一聚教程网
1,输出View HTML 字符串:
代码如下 | 复制代码 |
/// /// 描述:输出View HTML 字符串 /// /// /// 视图文件名 /// 母板页文件名 /// protected static string RenderViewToString(Controller controller, string viewName, string masterName) { IView view = ViewEngines.Engines.FindView(controller.ControllerContext, viewName, masterName).View; using (StringWriter writer = new StringWriter()) { ViewContext viewContext = new ViewContext(controller.ControllerContext, view, controller.ViewData, controller.TempData, writer); viewContext.View.Render(viewContext, writer); return writer.ToString(); } } |
2,输出PartialView HTML 字符串:
代码如下 | 复制代码 |
/// /// 描述:输出PartialView HTML 字符串 /// /// /// 部分视图文件名 /// protected static string RenderPartialViewToString(Controller controller, string partialViewName) { IView view = ViewEngines.Engines.FindPartialView(controller.ControllerContext, partialViewName).View; using (StringWriter writer = new StringWriter()) { ViewContext viewContext = new ViewContext(controller.ControllerContext, view, controller.ViewData, controller.TempData, writer); viewContext.View.Render(viewContext, writer); return writer.ToString(); } } |
相关文章
- 原神欧洛伦怎么培养 原神欧洛伦培养攻略介绍 11-22
- 炉石传说跳费大哥德卡组怎么样 炉石传说跳费大哥德卡组推荐介绍 11-22
- 蛋仔派对曙光龙女芙瑞怎么样 11-22
- 原神恰斯卡怎么养成 11-22
- 光遇11.22免费魔法有什么 11-22
- 光遇11.22大蜡烛在哪里 11-22