Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Apr 05, 2012 06:18 AM by zuperboy90
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
All-Star
18647 Points
2647 Posts
Apr 04, 2012 02:58 PM|LINK
What exactly are you trying to accomplish?
Also, what do you mean by an embedded view?
Apr 05, 2012 06:18 AM|LINK
I am using Portable View Areas with MvcContrib.
For this to work, all the views (and content files) from a portable area project needs to have Build Action set to Embeded Resource, so when they are compiled into the projects dll.
I am trying to "access" one of this views from code behind.
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
CodeHobo
All-Star
18647 Points
2647 Posts
Re: Accessing an Embeded View from code behind
Apr 04, 2012 02:58 PM|LINK
What exactly are you trying to accomplish?
Also, what do you mean by an embedded view?
Blog | Twitter : @Hattan
zuperboy90
Participant
977 Points
819 Posts
Re: Accessing an Embeded View from code behind
Apr 05, 2012 06:18 AM|LINK
I am using Portable View Areas with MvcContrib.
For this to work, all the views (and content files) from a portable area project needs to have Build Action set to Embeded Resource, so when they are compiled into the projects dll.
I am trying to "access" one of this views from code behind.