在.NET Core中以字符串形式返回视图
我找到了一些文章,介绍如何在ASP.NET中将视图返回到字符串,但是无法隐蔽任何内容以使其能够在.NET Core中运行 public static string RenderViewToString(this Controller controller, string viewName, object model) { var context = controller.ControllerContext; if (string.IsNullOrEmpty(viewName)) viewName = context.RouteData.GetRequiredString("action"); var viewData = new ViewDataDictionary(model); using (var sw = new StringWriter()) { var viewResult = ViewEngines.Engines.FindPartialView(context, viewName); var viewContext = new ViewContext(context, viewResult.View, viewData, new TempDataDictionary(), sw); viewResult.View.Render(viewContext, …