Reputation: 756
I have defined a layout template .cshtml for my site using the following method:
@{ Layout = "InsideLayout"; }
I am now trying to grab the request url to figure out what navigation menu item should be marked as active at any point in time. It however looks like the Request object is null (however unable to get a break point in the view, so not 100% that's the issue, but pretty sure).
To me, it seems that the current Request object should be populated properly in a Layout view, so it can some context sensitive markup in it, but as is this doesn't seem possible. Is there a specific class that the layout must inherit from to enable this, or is what I'm seeing the expected behavior?
Another option I was thinking might work, is to create a custom service to back the layout view. I tried this, however I wasn't able to get the service code to execute when a page using the layout was loaded. Is this even possible?
Upvotes: 1
Views: 227
Reputation: 1038770
Normally you should have access to the Request inside the view. But a better way to do that is to pass it in the model. Simply add the information as a property to the model that you are passing to this view and have the service populate it.
Upvotes: 1