Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Participant
977 Points
819 Posts
Apr 04, 2012 12:47 PM|LINK
Hello,
Currently, i can access a page from code behind doing like this:
private string GetViewPageHtml(Controller controller, object model, string viewName) { ViewEngineResult result = ViewEngines.Engines.FindPartialView(controller.ControllerContext, viewName); if (result.View == null) throw new Exception(string.Format("View Page {0} was not found", viewName)); controller.ViewData.Model = model; StringBuilder sb = new StringBuilder(); using (StringWriter sw = new StringWriter(sb)) { using (HtmlTextWriter output = new HtmlTextWriter(sw)) { ViewContext viewContext = new ViewContext(controller.ControllerContext, result.View, controller.ViewData, controller.TempData, output); result.View.Render(viewContext, output); } } return sb.ToString(); }
It works for normal pages.
I need to do the same thing, but for an embeded view page.
How can i do this?
Thank you
zuperboy90
Participant
977 Points
819 Posts
Accessing an Embeded View from code behind
Apr 04, 2012 12:47 PM|LINK
Hello,
Currently, i can access a page from code behind doing like this:
private string GetViewPageHtml(Controller controller, object model, string viewName) { ViewEngineResult result = ViewEngines.Engines.FindPartialView(controller.ControllerContext, viewName); if (result.View == null) throw new Exception(string.Format("View Page {0} was not found", viewName)); controller.ViewData.Model = model; StringBuilder sb = new StringBuilder(); using (StringWriter sw = new StringWriter(sb)) { using (HtmlTextWriter output = new HtmlTextWriter(sw)) { ViewContext viewContext = new ViewContext(controller.ControllerContext, result.View, controller.ViewData, controller.TempData, output); result.View.Render(viewContext, output); } } return sb.ToString(); }It works for normal pages.
I need to do the same thing, but for an embeded view page.
How can i do this?
Thank you