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 NancyLiteRazorModule(RazorEnginePlus razor, string root = "") : base(root) { Razor = razor; View = new NancyLiteViewRenderer(this, razor); ViewBag = new RazorExpandoObject(); Model = new RazorExpandoObject(); }
public NancyLiteViewRenderer(NancyLiteRazorModule module, RazorEnginePlus razor) { _razor = razor; _module = module; }
public void Initialize(RazorEnginePlus compiler) { _compiler = compiler; }