Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Justin Spradlin 139 posts 347 karma points
    May 30, 2011 @ 16:54
    Justin Spradlin
    0

    Getting the media url in Razor

    I may be missing something really simple here, but I cannot seem to get the picked media value in a razor expression. 
    I am using the S3 provider and want to get the media url so I can use it with JW Player. I have a property on my document called "Video" which is a "Amazon S3 File" data type. I can add the video using the picker, but then I render the document using Razor expression @Model.Video the content is rendered as "umbraco.MacroEngines.DynamicXml". 
    I can see that the value is in the database. I have also tried @Model.Video.Value, @Model.Video.value and I cannot figure it out. How do I get the value of the dynamic xml property?
    Thanks,
    Justin

  • Morten Christensen 596 posts 2773 karma points admin hq c-trib
    May 30, 2011 @ 17:07
    Morten Christensen
    0

    Hi Justin,

    This has to do with how Razor recognizes the value of the property. In the UMP provider the value is saved as CDATA, which seems to cause a little confusion.

    See this post for reference on the same issue: http://our.umbraco.org/forum/developers/razor/17897-How-to-iterate-DynamicXml

    Sounds like @Model.Video.Value should work though, as Video is the name of your Amazon property.

    - Morten

  • Justin Spradlin 139 posts 347 karma points
    May 30, 2011 @ 18:09
    Justin Spradlin
    0

    I read that post and was not able to make it work. 

    This is the content that is stored in the database:

    <Lecture id="1136" parentID="1106" level="3" writerID="0" 
            creatorID="0" nodeType="1102" template="1103" sortOrder="2" 
            createDate="2011-05-27T22:14:30" updateDate="2011-05-30T10:26:56" 
            nodeName="Second Lecture" urlName="second-lecture" 
            writerName="admin" creatorName="admin" 
            path="-1,1061,1106,1136" isDoc="">
        <metaDescription>This is a second lecture</metaDescription>
        <bodyText><![CDATA[
        <p>Here is the text of the second lecture. Trying to use S3 Streaming!</p>
        ]]></bodyText>
        <galleryID></galleryID>
        <video>
            <value dataTypeId="1135">
                <![CDATA[rtmp.mydomain.com/videos/demo.mp4]]>
            </value>
        </video>
    </Lecture>
    

     

    This is my razor template

     

    @using System.Xml.Linq;
    @using umbraco.MacroEngines
    
    <div>  
      <h3>@Model.Name</h3>
      <div>
        @Model.BodyText
      </div>
      <div>
        Video
        @Model.Video.Value
      </div>
    </div>
    

     

    When ever I render the page I get 'umbraco.MacroEngines.DynamicXml' does not contain a definition for 'Value'. What am I doing wrong?

     

    If I change the template to use

    @Model.Video.ToXml()
    

     

    The browser renders

     

    Video <value dataTypeId="1135"><![CDATA[rtmp.mydomain.com/videos/demo.mp4]]></value>
    
  • Justin Spradlin 139 posts 347 karma points
    May 30, 2011 @ 18:11
    Justin Spradlin
    0

    It also does not work if I use @Model.video.value.

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    May 30, 2011 @ 20:03
    Dirk De Grave
    1

    Justin,

    Here's a quick solution (may not be the most optimal solution...)

    var src = XDocument.Parse(Model.Video).Descendants("value").FirstOrDefault().Value;

    which should get you the value of the first <value> node.

     

    Hope this helps.

    Regards,

    /Dirk

     

  • Justin Spradlin 139 posts 347 karma points
    May 30, 2011 @ 21:20
    Justin Spradlin
    0

    Dirk,

     

    Thank you for the suggestion. I had to modify it a little to make it work. This is what I came up with. This probably not the most optimal but let me know if you have any ideas.

     

    @XDocument.Parse(Model.Video.ToXml()).Element("value").Value

    When I called XDocument.Parse(Model.Video) it said that the Parse function had invalid arguments. So that is why I added the ToXml() to the argument.

Please Sign in or register to post replies

Write your reply to:

Draft