This project is read-only.

model.title vs. layout.cshtml

Topics: General
Apr 5, 2011 at 12:23 PM


I'm attempting to get a title for the content of each page but reference model.title in layout.cshtml.


Is this possible? If not then could someone tell me how to go about acheiving this?

My problem is that the html involved in making up the page(s) requires me to place some of the structure in layout.cshtml, this being the place where i need to display model.title


Any help is much appreiciated.




Apr 5, 2011 at 1:53 PM
Edited Apr 5, 2011 at 3:11 PM

I needed to this as well, it's not as straightforward as it sounds :)

The title is stored in the RoutablePart. This means the template that generates it is Parts_RoutableTitle. (This shape is generated from the RoutablePartDriver)

The way I achieved this was by pushing Parts_RoutableTitle into the Header zone of my layout. Although is there a specific reason why you just want the title as a string rather than the actual template?

Edit: Fixed plurals

Apr 5, 2011 at 2:26 PM
Edited Apr 5, 2011 at 2:27 PM

I am trying to do this but add Part_RoutableTitle into the BeforeContent zone


WorkContext.Layout.BeforeContent.Add(New.Part_RoutableTitle(), "10"); // page title


I dunno if this is correct but it does not generate an error. how do I now access this in layout.cshtml ?




Apr 5, 2011 at 3:08 PM

In layout it should display with this line:


That will render anything in the BeforeContent zone, assuming what you did worked.

I'm just wondering where exactly did you add that code?

I ended up getting it working by supplementing my own RoutePart driver but I've since discovered there are probably simpler ways especially if you needed to do a lot of this stuff:

 public class RoutePartDriver : ContentPartDriver<RoutePart>

private IWorkContextAccessor _workContextAccessor;
public RoutePartDriver(IWorkContextAccessor workContextAccessor)
_workContextAccessor = workContextAccessor;

protected override DriverResult Display(RoutePart part, string displayType, dynamic shapeHelper)
var context = _workContextAccessor.GetContext();
if (displayType == "Detail")
var headShape1 =
shapeHelper.Parts_Header_RoutableTitle(ContentPart: part, Title: part.Title, Path: part.Path);
context.Layout.Zones["Header"].Add(headShape1, "1");
return new DriverResult();


Also note that I've named the shape Parts_Header_RoutableTitle. This meant I could use to hide the original Parts_RoutableTitle as well as adjusting the position of this one if I needed.

I reached the above method after discussion in this thread:

You can see this other thread for a possibly better way (towards the end):

But, I haven't yet tested that last method since I've already got everything working how I want with drivers.

Apr 5, 2011 at 3:10 PM
Edited Apr 5, 2011 at 3:12 PM

BTW it should be Parts plural, I got it wrong in my first reply.