Copied to clipboard

Flag this post as spam?

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


  • hetaurhet 245 posts 267 karma points
    Feb 12, 2012 @ 11:18
    hetaurhet
    0

    umbraco.MacroEngines.DynamicMedia.DynamicMedia() has invalid arguments error

    hello

    I have following razor script...

    @using umbraco.MacroEngines;
    @inherits umbraco.MacroEngines.DynamicNode
    @inherits umbraco.MacroEngines.DynamicNodeContext
    <script src="/scripts/jquery.easing.1.3.js" type="text/javascript"></script>
    <script src="/scripts/akram-treasure.js" type="text/javascript"></script>


    @{
      var Treasure = @Model.NodeById(1101);
    <div class="akram-treasure">
      
      @foreach(var node in @Treasure.Children)
      {
        dynamic link = new DynamicMedia(@node.akramTreasureThumbImage);
     
        string str = @node.content;
        <div class="qitem">
          <a href="@node.NiceUrl" target="_blank"><img src="@link.umbracoFile" alt="@node.PageHeading" title="@node.PageHeading" width="126" height="126"/></a>
          <span class="caption">
            <h4>@node.PageHeading</h4>
            <p>str.Substring(0,index+1)</p>
          </span>
        </div>
      }

    </div>

     }

    this gives error on page as follows

    Error loading Razor Script AkramTreasure.cshtml
    The best overloaded method match for 'umbraco.MacroEngines.DynamicMedia.DynamicMedia(umbraco.MacroEngines.DynamicBackingItem)' has some invalid arguments

    What is wrong in this?

  • Douglas Ludlow 210 posts 366 karma points
    Feb 12, 2012 @ 16:09
    Douglas Ludlow
    0

    Which version of Umbraco are you using?

    Instead of using the DynamicMedia constructor, try using the Library.MediaById() or Model.MediaById() shorthand methds:

    @foreach(var node in Treasure.Children)
    {
    dynamic link = Library.MediaById(node.akramTreasureThumbImage);

    ...
    }
  • hetaurhet 245 posts 267 karma points
    Feb 13, 2012 @ 06:37
    hetaurhet
    0

    hello...

    I am using umbraco 4.7.1. Now, it is not showing razor error. So ur solution was a bit helpful. But It is not fetching  image.

    In firebug it shows the line .... <a href="@node.NiceUrl" target="_blank"><img src="@link.umbracoFile" alt="@node.PageHeading" title="@node.PageHeading" width="126" height="126"/></a> .... as ....

    <a target="_blank" href="/magic-box/dadashri's-akram-treasure/night-club/">a>

    What's the problem?

  • hetaurhet 245 posts 267 karma points
    Feb 13, 2012 @ 06:49
    hetaurhet
    0

    Solved the problem...  I think u missed @ sign in line u mentioned. Now, it works. Thanks anyways.

    dynamic link = Model.MediaById(@node.akramTreasureThumbImage);

  • hetaurhet 245 posts 267 karma points
    Feb 13, 2012 @ 07:30
    hetaurhet
    0

    I dont know again the problem is coming...

    used the line said by you again

    dynamic link =Library.MediaById(node.akramTreasureThumbImage);

    now it shows.....

    Error loading Razor Script AkramTreasure.cshtmlCannot get MediaById without an id
  • Douglas Ludlow 210 posts 366 karma points
    Feb 13, 2012 @ 09:58
    Douglas Ludlow
    0

    Hmm... sounds like the problem is with the node.akramTreasureThumbImage property. What datatype is that using? Perhaps one of your Treasure.Children doesn't have it set?

    When I'm debugging razor scripts I find it handy to output the values directly just to see what they are. So try commenting out the link line and add a couple lines as follows to determine what's going on:

    @{
      var Treasure = @Model.NodeById(1101);
    <div class="akram-treasure">
      @foreach(var node in @Treasure.Children)
      {     //dynamic link = new DynamicMedia(@node.akramTreasureThumbImage);
        <div>@node.akramTreasureThumbImage</div>
        <div>@node.akramTreasureThumbImage.GetType()</div>
       
        ...   }
    </div>
    }
  • hetaurhet 245 posts 267 karma points
    Feb 13, 2012 @ 10:10
    hetaurhet
    0

    thank you. It was like one one the nodes was not assigned image. And so the problem was coming.

  • Douglas Ludlow 210 posts 366 karma points
    Feb 13, 2012 @ 14:36
    Douglas Ludlow
    0

    Glad I could help.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies