Render MVC Views in pages with different templates
Hi,
Basically - I want to know if it's possible to render different views for an MVC widget into pages that are based on different templates.
Long version:
I currently have an MVC widget with a single action - Index() - that renders out a list of items to the page as a horizontal scroller. The page that the widget is on consists of a number of such scrollers stacked on top of each other, and so there is very little vertical space allotted for each widget. I would like to add a details view - Show() - that will display more information about each of the items listed in scroller. The problem is that the default behavior of MVC widgets will try to put the resulting page from the Show() action into the short, wide spot allotted to the scroller. I have another template that we use for the rest of the site that is a much more standard layout; is it possible to have the Show() view render to a page using that template rather than to the page that the widget is located on with the highly-specialized horizontal scroller template?
Thanks,
Stuart
Hi,
Here is sample code how you can get page template for the current page:
Guid currentPageId = SiteMapBase.GetCurrentNode().PageId;
PageManager manager = PageManager.GetManager();
PageData pageData = manager.GetPageData(currentPageId);
var templateName = pageData.Template.Title;
Hi Stoimen,
Thanks for the example; however, that's not exactly the question I'm trying to answer. I'm not trying to pick a view to render depending on the template; I want to render the view to a page that uses a different template than the page the widget is included in.
For instance: the widget is included on the homepage: example.com/, and the homepage uses the "HomepageTemplate". When an item in the Index() (default) view of the widget is clicked, I would like the Details() view to render to a *different page*, ie example.com/item_details, that uses a *different template*, ie "GenericSubpageTemplate", so that I can show the item details in a "normal" page. The default action for MVC widgets is to render the request view in the same content block in the same page in which the widget is included.
The content block in which the widget is placed on the home page is very short, but quite wide. It works great for the index view that displays a horizontal list of items, but doesn't make sense for displaying detail - article text, publication information, etc.
Thanks,
Stuart