0

This question is about the CMS Composite C1 and the MvcPlayer functionality.

I am using a Razor page template for my pages and embed several MVC actions in the layout by using

@Function("Composite.AspNet.MvcPlayer", new { Path = "/Controller/Action" })

This works pretty well in general, but for some reason the MvcPlayer renders not only the View returned by the action itself, but encloses the View in

<html><head></head><body>[View content is here]</body></html>

This obviously screws up my markup, because I am nesting html-blocks in the site. Why is this happening and is there a way to stop the MvcPlayer from creating the additional markup?

As this appears to be solely a Composite C1 issue, I'm linking to the source code for Composite C1 in the hopes that someone will be able to tell me if it's a Composite C1 bug or if I just am using it incorrectly.

George Stocker
  • 57,289
  • 29
  • 176
  • 237
magnattic
  • 12,638
  • 13
  • 62
  • 115
  • Are you returning a full view (with layout specified) using `return View();`, or a partial view `return PartialView();`? – iCollect.it Ltd Oct 20 '14 at 13:23
  • In the action method? I am returning View(), but no Layout specified in the View itself. – magnattic Oct 20 '14 at 13:30
  • If you do not specify one, you get the default layout specified in `_ViewStart.cshtml`... Use `return PartialView();` instead – iCollect.it Ltd Oct 20 '14 at 13:34
  • There is no _ViewStart.cshtml in my project (or in the folder) that could be the source for the additional markup. But I will try the PartialView solution anyway. – magnattic Oct 20 '14 at 13:39
  • Nope, no dice. Still renders the mysterious html tags. I am afraid they are created by the MvcPlayer function itself, but I don't get why they would be included in the final site. Somewhere something is going wrong (or I am just using it wrong). – magnattic Oct 20 '14 at 13:53
  • I am not familiar with MvcPlayer, but if they intended it to play in an iFrame they may have added the missing elements for that? – iCollect.it Ltd Oct 20 '14 at 14:40
  • There is probably a .cshtml page with that markup in - have you just tried a text search within the site directory for "..." etc? – niico Oct 20 '14 at 16:42
  • While I appreciate any responses trying to help me, I am afraid this is a problem very specific to Composite C1 and the MvcPlayer. I am pretty sure that this markup is created automatically and not by my own Views/Layouts. Please only respond if you are familiar with the CMS and its MVC interoperability. – magnattic Oct 21 '14 at 10:11
  • Looking at their source code, it appears that function is meant to return a whole XHTML document. You can fix it by wrapping it in an Extension method that trims the extraneous stuff. I can't give you more of an answer without actually diving into the problem. This is just a cursory look at their Source. – George Stocker Oct 21 '14 at 12:44
  • Hi, thanks for looking into it. Trimming it is the way I am doing it right now, and it works for use in the layout. But if I embed the MvcPlayer in a page through the C1 backend, he seems to expect the full XHTML page for whatever reason (and throws an error if I trim it there). The problem is that it still renders the html tags in the final page if embedded this way. I don't think that's intended (or at least I hope so). – magnattic Oct 21 '14 at 12:49
  • @atticae You should still be able to use an extension method in the view to capture the output and fix it; it sucks, I know. – George Stocker Oct 21 '14 at 12:57
  • The final page is rendered by C1 so I can't really influence what happens to the markup when I embed the function in the page itself. (Instead of the Layout cshtml) I have to somehow get the function to work both in the Backend (where it needs the XHTML apparently) and render without HTML tags in the final page, so I don't really have any clue how to fix that. – magnattic Oct 21 '14 at 13:01

1 Answers1

1

If you look at the code for MvcPlayer, you will find the following template file:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:in="http://www.composite.net/ns/transformation/input/1.0" xmlns:lang="http://www.composite.net/ns/localization/1.0" xmlns:f="http://www.composite.net/ns/function/1.0" xmlns="http://www.w3.org/1999/xhtml" exclude-result-prefixes="xsl in lang f">
    <xsl:template match="/">
        <html>
            <head>
            </head>
            <body>
                <f:function name="Composite.AspNet.MvcPlayer.Render">
                    <f:param name="Path" value="{/in:inputs/in:param[@name='Path']}" />
                </f:function>
            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>

You need to figure out how to override the default template with one of your own. There's likely somewhere you need to drop a modified XSL file, but I can't find it at the moment.

Moshe Katz
  • 15,992
  • 7
  • 69
  • 116
  • Thanks, that explains where the markup is coming from. But as I said in the comments above, replacing it won't work for cases where I embed the MvcPlayer directly in the C1Page through the CMS backend, because the additional markup is expected there. (An error is thrown if it's not there) So this seems to be intended behaviour, I just have to figure out why the markup is still rendered in the final page. I have a starting point now though, so thanks a lot! – magnattic Oct 22 '14 at 10:31
  • I suspect it has to do with the fact that my layout page is HTML5 and not XHTML. That probably screws up the XSLT transformation that should be happening. – magnattic Oct 22 '14 at 10:32
  • Got it to work! My layout was missing the namespace in the html tag, so the XSLT function failed to combine the site with the function markup properly. I replaced `` with `` and now it merges the function head with the page head and body with body. – magnattic Oct 22 '14 at 13:54