Try our conversational search powered by Generative AI!

How can i get a reference to the current page within a view or layout?

Vote:
 

How can i get a reference to the current page within a simple view or layout? I tried "PageReference.SelfReference" but it just gives an exception.

#172801
Dec 12, 2016 19:56
Vote:
 

You can try  Request.RequestContext.GetContentLink().  that should get you what you are after.

#172807
Dec 13, 2016 4:48
Vote:
 

Normally you pass along the values you need in the viewmodel. So expanding the viewmodel with what you need in the view / layout should be your first bet.

Storing it in viewbag is an alternative, don't like that one much. I'm a bit old school. If you are using Alloy variant of viewmodels you will also get the current page as part of your viewmodel...

#172821
Dec 13, 2016 9:26
Vote:
 

Thank you Joshua, thats exactly what i need

#172826
Dec 13, 2016 9:30
Vote:
 

Live Daniel said though, normally i onl use request.requestcontext.getcontentlink when i don't have it available on the model which is hardly every or in a block and need to know what page I am on.  Hope that makes sense.  you should be sending at least a viewmodel to the view if you are not comfortable sending the full pagedata model to the view.

#173065
Dec 13, 2016 18:26
Vote:
 

Well the problem that i have is that on one page on the site there needs to be some javascripts put after the jquery and other scripts, so i cannot put these scripts in the block/page that will use them. Therefore on the root template (layout) i need to test for the selected page - as specified in the StartPage , and if this is the correct page i pop the scripts in to the output stream. They cannot be on every page, since the overhead is waaaay too much! My goal is to reduce overhead. This check has to happen for every page, so the layout would seem to be place to determine the boolean.

#173067
Dec 13, 2016 18:31
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.