How to check if a variable is defined in a Master file in ASP.NET MVC

Posted by Mortanis on Stack Overflow See other posts from Stack Overflow or by Mortanis
Published on 2010-06-05T04:18:01Z Indexed on 2010/06/05 6:32 UTC
Read the original article Hit count: 337

I've got a Site.Master file I've created to be my template for the majority of the site, with a navigation. This navigation is dynamically created, based on a recursive Entity (called Page) - Pages with a parentID of 0 are top level, and naturally each child carries it's parent's Id in that field.

I've created a quick little HTML Helper that accepts the ID of an Page and generates the nav by doing a foreach on the children that have a parentId matching the passed Id. On the majority of the site, I want the Site.Master to use a parentId of 0, but if I'm on a strongly typed View displaying a Page, I naturally want to use the Id of the page.

Is there a way to do such conditional logic in a Site.Master (and, does that violate MVC rules)? "If I'm on a strongly typed Page of /Page/{Id}, use the Id render nav, else use 0"

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about mvc