ProMesh.NET Quick Walkthrough - Part 7 - Rendering views at runtime


In our previous examples, you specified the layout and view as attributes for the controller class. This is fine in most cases, but sometimes you want to change the view at runtime. This is possible by just calling the method RenderView() in your code:

[Layout("master")]   // "master" is the default layout
[View("home")]        // "home" is the default view
public class Home : PageController
{
   public void Run(bool alternateLayout)
   {
      if (alternateLayout)
         RenderView("home2");
   }
}


Changing the layout is just as easy:

[Layout("master")]   // "master" is the default layout
[View("home")]        // "home" is the default view
public class Home : PageController
{
   public void Run(bool alternateLayout)
   {
      if (alternateLayout)
         ChangeLayout("master2");
   }
}


Next >> Setup/Teardown methods

Last edited Jul 30, 2007 at 4:32 PM by activa, version 2

Comments

No comments yet.