Best is to pass it or the properties you need from your controller to the view.
public ActionResult Index(PageData currentPage) { // code here }
You can also access it directly (bad pattern):
var contentRouteHelper = ServiceLocator.Current.GetInstance<IContentRouteHelper>(); contentRouteHelper.Content as PageData
Hope this helps.
Frederik
Thank you - although i am trying to get this in a view without a controller. Why is your second solution a bad pattern?
More logic in view. Logic should be contained in controller or even better in the service layer below controller. More logic in view => harder to read presentation and more difficult to maintain solution if logic is scattered around solution. Single responsibility principle, MVC pattern etc...
Hi Daniel,
The problem is that there is one block that requires some javascripts placed below the jquery and other scripts. I cannot put these scripts on every page because they are very heavy and will slow every page on the site, rather than just the page that has the javascript application on. I need some sort of switch within the layout that determines whether the current page is the one that needs the extra javascript. The page in question has a reference on the start page properties - so i am currently comparing in the head of the layout. Can you think of an alternative to this? Should i create a second layout and a custom page type that uses just this layout? Would this be a better solution?
Regards,
Marshall
Use a LayoutModel like in Alloy sample site, or an action method with the ChildActionAttribute.
Frederik