Search code examples
jqueryicollection

How to show ICollection count in jQuery tmpl?


In my POCO model, I have a collection property defined as

    public virtual ICollection<Position> Positions { get; set; }

Now, in my jquery tmpl, I'd like to show the count of Positions property in a jquery tmpl like

        <span class="Position">${Positions.Count}</span>

However, it shows nothing (empty) there. I don't get any error either. Is there a way to make it work?


Solution

  • add the method like:

    public virtual ICollection<Position> Positions { get; set; }
    public int Total { get { this.Positions.Count(); }
    

    in your code

    <span class="Position">${Total}</span>