Take the 2-minute tour ×
Tridion Stack Exchange is a question and answer site for Tridion developers and administrators. It's 100% free, no registration required.

We noticed that when debugging our MVC5 DD4T application the page controller gets executed more than once. The same breakpoint is hit multiple times and all component presentations get rendered twice.

The markup returned is also funky... there are multiple doctype declarations and multiple and tags rendered.

I've scanned the code to see if something is calling the page controller multiple times - nothing. I've also checked my area registration and routes configs, and those are all in order.

What could be causing this?

share|improve this question

1 Answer 1

up vote 9 down vote accepted

The problem with multiple doctype declarations can be caused by some standard mvc view behaviour.

In your mvc project, you can define a _viewstart.cshtml file. In here, you specify the default mvc "master page" (called "layout page") to use. This layout page will be outputted around all of your views that don't specifiy a custom layout. you can specify a custom layout page per view by adding this piece of code on top of your view

{@layout="../your-custom-layout.cshtml"}

you can also specify not to use a layout by putting this

{@layout=null}

Now, as all of your component cshtml views are usually in one subfolder, an easy fix for this is to add a new _viewstart.cshtml file in the root of the components view folder containing this piece of code

@{
    Layout = null;
}

As a result, you can have your page views have a standard layout.cshtml masterpage, and all of your components have no master page.

share|improve this answer
    
Thanks Harald. This certainly solves the funky markup problem. Regarding the page controller being hit multiple times, it is not a related issue. We realized that there is some well-hidden javascript that makes second call to the same page - so it's a non-issue. I'm marking your answer as correct. –  Nickoli Roussakov Aug 4 at 15:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.