Copied to clipboard

Flag this post as spam?

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


  • Jebastin 42 posts 91 karma points
    Sep 25, 2013 @ 12:47
    Jebastin
    0

    Exception: 'Object' does not contain a definition for 'Take'

    foreach (var mc in CurrentNode.hAuditSpotlight.Skip(SkipContents).Take(10))
    {
    }

    Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'object' does not contain a definition for 'Take' at CallSite.Target(Closure , CallSite , Object , Int32 ) at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1) at KPMGAudit.Web.MainContents.FetchMainContentsByCategory(String Category, Int32 StartsFrom) in XXX:line XXX

    If I use "Skip()" alone, it works; also "Take()" alone works, but while using both simultaneously throws the above exception.

    Any solution???!!!

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Sep 26, 2013 @ 08:00
    Jeavon Leopold
    0

    Hi, could you post a little more of your code, specifically what is CurrentNode and also what is hAuditSpotlight?

    Thanks,

    Jeavon

  • Kasper Dyrvig 246 posts 379 karma points
    Sep 26, 2013 @ 23:43
    Kasper Dyrvig
    0

    Just an idea: I think it would be better if you use Where instead of Skip...

    .Where("something something").Take(10)
  • Jebastin 42 posts 91 karma points
    Sep 30, 2013 @ 11:16
    Jebastin
    0

    Hi Jeavon,

    Thanks for your reply. I've posted a little more of my code here.

    CurrentNode = new DynamicNode().NodeById(1050);
    //CurrentNode.hAuditSpotlight is a Multi-Node Tree picker property.

    foreach(var mc in CurrentNode.hAuditSpotlight.Skip(SkipContents).Take(10))
    {
    }
  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Sep 30, 2013 @ 12:26
    Jeavon Leopold
    0

    Ok, you need to a fair bit more to get MNTP converted to objects so you can skip and take:

    @{
        var currentNode = Library.NodeById(1050);
    
        if (currentNode.HasValue("hAuditSpotlight"))
        {
            IEnumerable<DynamicNode> publishedNodeList = Library.NodesById(Model.hAuditSpotlight.Split(','));
            publishedNodeList = publishedNodeList.Where(x => x.GetType() != typeof(DynamicNull) && x.Id > 0);
            dynamic hAuditSpotlight = new DynamicNodeList(publishedNodeList);
    
            if (hAuditSpotlight.Any())
            {
                foreach (var item in hAuditSpotlight.Skip(1).Take(10))
                {                   
                    <p>@item.Name</p>      
                }               
            }
        }            
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft