diff --git a/core/core.services.yml b/core/core.services.yml
index 9a36139..da33ae9 100644
--- a/core/core.services.yml
+++ b/core/core.services.yml
@@ -290,7 +290,7 @@ services:
     arguments: ['@http_kernel']
   controller.dialog:
     class: Drupal\Core\Controller\DialogController
-    arguments: ['@http_kernel']
+    arguments: ['@http_kernel', '@router.dynamic']
   router_listener:
     class: Symfony\Component\HttpKernel\EventListener\RouterListener
     tags:
diff --git a/core/lib/Drupal/Core/ContentNegotiation.php b/core/lib/Drupal/Core/ContentNegotiation.php
index 500200c..da51ac5 100644
--- a/core/lib/Drupal/Core/ContentNegotiation.php
+++ b/core/lib/Drupal/Core/ContentNegotiation.php
@@ -40,6 +40,7 @@ public function getContentType(Request $request) {
     $first_found_format = FALSE;
     $priority = array('html', 'drupal_ajax', 'drupal_modal', 'drupal_dialog');
     foreach ($request->getAcceptableContentTypes() as $mime_type) {
+      error_log($mime_type);
       $format = $request->getFormat($mime_type);
       if (in_array($format, $priority, TRUE)) {
         return $format;
diff --git a/core/lib/Drupal/Core/Controller/DialogController.php b/core/lib/Drupal/Core/Controller/DialogController.php
index 4b26686..c5df6e3 100644
--- a/core/lib/Drupal/Core/Controller/DialogController.php
+++ b/core/lib/Drupal/Core/Controller/DialogController.php
@@ -9,6 +9,7 @@
 
 use Drupal\Core\Ajax\AjaxResponse;
 use Drupal\Core\Ajax\OpenDialogCommand;
+use Symfony\Cmf\Component\Routing\DynamicRouter;
 use Symfony\Component\HttpFoundation\Request;
 use Symfony\Component\HttpKernel\HttpKernelInterface;
 
@@ -25,12 +26,23 @@ class DialogController {
   protected $httpKernel;
 
   /**
-   * Constructs a new HtmlPageController.
+   * The Dynamic router.
+   *
+   * @var \Symfony\Cmf\Component\Routing\DynamicRouter
+   */
+  protected $dynamicRouter;
+
+  /**
+   * Constructs a new DialogController.
    *
    * @param \Symfony\Component\HttpKernel\HttpKernelInterface $kernel
+   *   The kernel.
+   * @param \Symfony\Cmf\Component\Routing\DynamicRouter $router
+   *   The router.
    */
-  public function __construct(HttpKernelInterface $kernel) {
+  public function __construct(HttpKernelInterface $kernel, DynamicRouter $router) {
     $this->httpKernel = $kernel;
+    $this->dynamicRouter = $router;
   }
 
   /**
@@ -38,13 +50,11 @@ public function __construct(HttpKernelInterface $kernel) {
    *
    * @param \Symfony\Component\HttpFoundation\RequestRequest $request
    *   The request object.
-   * @param callable $content
-   *   The body content callable that contains the body region of this page.
    *
    * @return \Symfony\Component\HttpFoundation\Response
    *   A response object.
    */
-  protected function forward(Request $request, $content) {
+  protected function forward(Request $request) {
     // @todo When we have a Generator, we can replace the forward() call with
     // a render() call, which would handle ESI and hInclude as well.  That will
     // require an _internal route.  For examples, see:
@@ -54,12 +64,34 @@ protected function forward(Request $request, $content) {
     // We need to clean up the derived information and such so that the
     // subrequest can be processed properly without leaking data through.
     $attributes->remove('system_path');
+    $attributes->set('dialog', TRUE);
 
     // Remove the accept header so the subrequest does not end up back in this
     // controller.
-    $request->headers->remove('accept');
+    $request->headers->remove('Accept');
+    // Remove the X-Requested-With header so the subrequest is not mistaken for
+    // an ajax request.
+    $request->headers->remove('X-Requested-With');
+
+    // Re-enhance the routes with the help of the dynamic router.
+    $defaults = $attributes->all();
+    unset($defaults['_controller']);
+    // Create a duplicate request for forwarding and enhancing. We can't use the
+    // existing request as the protected acceptableContentTypes property has
+    // been set already at this stage and cannot be flushed.
+    $sub_request = $request->duplicate($request->query->all(), NULL, $defaults);
+    foreach ($this->dynamicRouter->getRouteEnhancers() as $enhancer) {
+      // Allow enhancers to run-again, other than the ParamConverterManager
+      // which we exclude because of a) they cannot be run again and b) it would
+      // be poor performance to do so.
+      if (get_class($enhancer) !== 'Drupal\\Core\\ParamConverter\\ParamConverterManager') {
+        $defaults = $enhancer->enhance($defaults, $sub_request);
+      }
+    }
 
-    return $this->httpKernel->forward($content, $attributes->all(), $request->query->all());
+    // Set the controller on the sub-request based on the enhancers.
+    $sub_request->attributes->set('_controller', $defaults['_controller']);
+    return $this->httpKernel->handle($sub_request, HttpKernelInterface::SUB_REQUEST);
   }
 
   /**
@@ -67,14 +99,12 @@ protected function forward(Request $request, $content) {
    *
    * @param \Symfony\Component\HttpFoundation\RequestRequest $request
    *   The request object.
-   * @param callable $_content
-   *   The body content callable that contains the body region of this page.
    *
    * @return \Drupal\Core\Ajax\AjaxResponse
    *   AjaxResponse to return the content wrapper in a modal dialog.
    */
-  public function modal(Request $request, $_content) {
-    return $this->dialog($request, $_content, TRUE);
+  public function modal(Request $request) {
+    return $this->dialog($request, TRUE);
   }
 
   /**
@@ -82,20 +112,18 @@ public function modal(Request $request, $_content) {
    *
    * @param \Symfony\Component\HttpFoundation\RequestRequest $request
    *   The request object.
-   * @param callable $_content
-   *   The body content callable that contains the body region of this page.
    * @param bool $modal
    *   (optional) TRUE to render a modal dialog. Defaults to FALSE.
    *
    * @return \Drupal\Core\Ajax\AjaxResponse
    *   AjaxResponse to return the content wrapper in a dialog.
    */
-  public function dialog(Request $request, $_content, $modal = FALSE) {
-    $subrequest = $this->forward($request, $_content);
+  public function dialog(Request $request, $modal = FALSE) {
+    $subrequest = $this->forward($request);
     if ($subrequest->isOk()) {
       $content = $subrequest->getContent();
       // @todo Remove use of drupal_get_title() when
-      //  http://drupal.org/node/1871596 is in.
+      //   http://drupal.org/node/1871596 is in.
       $title = drupal_get_title();
       $response = new AjaxResponse();
       // Fetch any modal options passed in from data-dialog-options.
diff --git a/core/lib/Drupal/Core/Controller/HtmlFormController.php b/core/lib/Drupal/Core/Controller/HtmlFormController.php
index 7eb85f3..9aea732 100644
--- a/core/lib/Drupal/Core/Controller/HtmlFormController.php
+++ b/core/lib/Drupal/Core/Controller/HtmlFormController.php
@@ -63,6 +63,9 @@ public function content(Request $request, $_form) {
 
     $form_id = _drupal_form_id($form_object, $form_state);
     $form = drupal_build_form($form_id, $form_state);
+    if ($request->attributes->get('dialog')) {
+      return drupal_render($form);
+    }
     return new Response(drupal_render_page($form));
   }
 
diff --git a/core/lib/Drupal/Core/Routing/Enhancer/ContentControllerEnhancer.php b/core/lib/Drupal/Core/Routing/Enhancer/ContentControllerEnhancer.php
index c355cc7..f9eeb98 100644
--- a/core/lib/Drupal/Core/Routing/Enhancer/ContentControllerEnhancer.php
+++ b/core/lib/Drupal/Core/Routing/Enhancer/ContentControllerEnhancer.php
@@ -48,8 +48,12 @@ public function __construct(ContentNegotiation $negotiation) {
    * {@inheritdoc}
    */
   public function enhance(array $defaults, Request $request) {
-    if (empty($defaults['_controller']) && !empty($defaults['_content'])) {
-      $type = $this->negotiation->getContentType($request);
+    // If no controller is set and either a) _content is set or the request is
+    // for a dialog or modal.
+    if (empty($defaults['_controller']) &&
+      ($type = $this->negotiation->getContentType($request)) &&
+      (!empty($defaults['_content']) ||
+      in_array($type, array('drupal_dialog', 'drupal_modal')))) {
       if (isset($this->types[$type])) {
         $defaults['_controller'] = $this->types[$type];
       }
