//---------------------------------------------------------------------
        /// <summary>
        
/// return the rendered view in HTML
        
/// </summary>
        
/// <param name="context"></param>
        
/// <param name="viewName"></param>
        
/// <param name="model"></param>
        
/// <returns></returns>
        //---------------------------------------------------------------------
        public static string RenderViewToString(ControllerContext context, string viewName, object model)
        {
            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, sw);

                return sw.GetStringBuilder().ToString();
            }
        }
posted on 2017-02-27 16:43 Ying-er 阅读(27) 评论(0)  编辑  收藏 所属分类: .Net

只有注册用户登录后才能发表评论。


网站导航: