mvc生成靜態頁 獲取controller的HTML
阿新 • • 發佈:2019-01-05
public string GetViewHtml(Controller controller, string viewName, string masterName) { IView view = ViewEngines.Engines.FindView(controller.ControllerContext, viewName, masterName).View; if (view == null) return ""; 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(); } }
// 引數1 控制器物件 引數2 檢視名 引數3模板頁名稱
string htmlcode = GetViewHtml(this, "NewsInfo", "_Layout");