MVC 读取指定视图HTML 代码结构
public static class ControllerExtensions { private static readonly Regex m_regex = new Regex(@"(?<=[^])\t{2,}|(?<=[>])\s{2,}(?=[<])|(?<=[>])\s{2,11}(?=[<])|(?=[\n])\s{2,}"); public static string RenderView(this Controller controller, string viewName, object model, string master = null) { var vd = new ViewDataDictionary(); foreach (var item in controller.ViewData.Keys) { vd.Add(item, controller.ViewData[item]); } vd.Model = model; using (StringWriter sw = new StringWriter()) { ViewEngineResult viewResult = ViewEngines.Engines.FindView(controller.ControllerContext, viewName, master); ViewContext viewContext = new ViewContext(controller.ControllerContext, viewResult.View, vd, controller.TempData, sw); viewResult.View.Render(viewContext, sw); return m_regex.Replace(sw.GetStringBuilder().ToString(), string.Empty); } } }
一只站在树上的鸟儿,从来不会害怕树枝会断裂,因为它相信的不是树枝,而是它自己的翅膀。与其每天担心未来,不如努力做好现在。