public void Render(ViewContext viewContext, TextWriter writer) { Page page = new Page(); Control ctl = page.LoadControl(ViewPath); if (ctl == null) { throw new InvalidOperationException(string.Format("指定的用户控件 {0} 没有找到。", ViewPath)); } // 将用户控件放在Page容器中。 page.Controls.Add(ctl); PartialCachingControl mycachectl = ctl as PartialCachingControl;//如果有 写outputcache指令 Control temp = ctl; if (mycachectl != null) { Page_request.FastSetValue(page, viewContext.HttpContext.Request);//将当前的Request 写入当前页面 page.DesignerInitialize(); temp = mycachectl.CachedControl; } ViewUserControlBase myctl = temp as ViewUserControlBase; if (myctl != null) { myctl.ViewContext = viewContext; } HtmlTextWriter write = new HtmlTextWriter(writer, string.Empty); page.RenderControl(write); }
protected override void RenderView(ViewContext viewContext, TextWriter writer, object instance) { ViewUserControlBase viewUserControl = instance as ViewUserControlBase; if (viewUserControl != null) { var oldWriter = viewContext.Writer; viewContext.Writer = writer; this.RenderViewUserControl(viewContext, viewUserControl); viewContext.Writer = oldWriter; } else { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "视图:{0}必须派生于ViewUserControl, ViewUserControl<TModel>", new object[] { base.ViewPath })); } }
private void RenderViewUserControl(ViewContext context, ViewUserControlBase control) { control.ViewContext = context; control.RenderView(context); }
public ViewUserControlContainerPage(ViewUserControlBase userControl) { this._userControl = userControl; }