예제 #1
0
파일: Layout.cs 프로젝트: zhq0131/CMS
 private void Parse(string body)
 {
     if (!string.IsNullOrEmpty(body))
     {
         var parsedPositions = TemplateEngines.GetEngineByName(EngineName).GetLayoutPositionParser().Parse(body);
         positions = new List <LayoutPosition>();
         foreach (var position in parsedPositions)
         {
             positions.Add(new LayoutPosition()
             {
                 ID = position
             });
         }
     }
 }
예제 #2
0
        internal IHtmlString RenderViewInternal(HtmlHelper htmlHelper, string viewPath, ViewDataDictionary viewData, object model)
        {
            if (string.IsNullOrEmpty(viewPath))
            {
                throw new ArgumentException("", "viewPath");
            }
            ViewDataDictionary dictionary = null;

            if (model == null)
            {
                if (viewData == null)
                {
                    dictionary = new ViewDataDictionary(htmlHelper.ViewData);
                }
                else
                {
                    dictionary = new ViewDataDictionary(viewData);
                }
            }
            else if (viewData == null)
            {
                dictionary = new ViewDataDictionary(model);
            }
            else
            {
                dictionary = new ViewDataDictionary(viewData)
                {
                    Model = model
                };
            }
            StringWriter writer = new StringWriter(CultureInfo.CurrentCulture);

            ViewContext viewContext = new ViewContext(htmlHelper.ViewContext, htmlHelper.ViewContext.View, dictionary, htmlHelper.ViewContext.TempData, writer);

            TemplateEngines.GetEngineByFileExtension(Path.GetExtension(viewPath)).CreateView(htmlHelper.ViewContext.Controller.ControllerContext, viewPath, null).Render(viewContext, writer);

            return(new HtmlString(writer.ToString()));
        }