public string RunSub(RazorEnginePlus razor, ref dynamic viewBag, object model = null) { if (model != null && model.IsAnonymous()) { model = new AnonymousTypeWrapper(model); } var instance = (RazorEngineTemplateBase)Activator.CreateInstance(templateType); #if !DEBUG if (instance == null) { return(""); } #endif instance.Html.Initialize(razor); instance.Model = model; instance.ViewBag = ViewBagCombine.Combine(instance.ViewBag, viewBag); instance.ExecuteAsync().Wait(); viewBag = ViewBagCombine.Combine(viewBag, instance.ViewBag); //获取instance.Layout必须在 instance.ExecuteAsync().Wait();之后否则无法取值 if (!string.IsNullOrEmpty(instance.Layout)) { return(razor.RenderRawSub(instance.Layout, ref instance.ViewBag, instance.Model)); } var result = instance.Result(); return(result); }
public virtual string Partial(string viewName, dynamic model = null) { if (_compiler == null) { return(null); } return(_compiler.RenderRawSub(viewName, ref _viewBag, model)); }