Filter gives System.ArgumentException when adding a column from Model that is .Count()

2 posts, 0 answers
  1. Peng
    Peng avatar
    10 posts
    Member since:
    Aug 2010

    Posted 28 Jun Link to this post

    Hi there,

    I have encountered this problem and can not fix the filter for these two columns. 

    If I use filter for these two columns: EnrolledNumber and WaitListNumber, I will get

    Internet Server Error

    Invalid Property or Field - 'EnrolledNumber' for type: Class

    If I disabled both sortable and filter for these two columns, everything else will work fine.

    How can I make the filter work and at the same time the program will not lag or become ridiculously slow?

     

    The following is my code.

     

    Model

    EnrolledNumber = model.ClientClasses.Where(i => i.IsActive == true).Count();
    WaitListNumber = model.ClientClasses.Where(i => i.IsActive == false).Count();

    [Display(Name = "Enrolled")]
    public int EnrolledNumber { get; set; }
    [Display(Name = "WaitList")]
    public int WaitListNumber { get; set; }

    View

    columns.Bound(i => i.EnrolledNumber).Width(90).Title("Enrolled");
    columns.Bound(i => i.WaitListNumber).Width(90).Title("WaitList");

    Controller

    public ActionResult Read_Classes([DataSourceRequest] DataSourceRequest request, bool isCurrent, bool isPending, bool isFinished)
    {
        IQueryable<Class> items = DbContext.Classes.Where(i => i.IsActive);
        if (!isPending)
            items = items.Where(i => !i.Pending);
        if (!isFinished)
            items = items.Where(i => !i.Finished);
        if (!isCurrent)
            items = items.Where(i => i.Finished || i.Pending);
        return Json(items.ToDataSourceResult(request, i => new ClassListViewModel(i)));
    }

    I also get

    An exception of type 'System.ArgumentException' occurred in Kendo.Mvc.dll but was not handled in user code

    in Visual Studio for first time

     

    Thank you

  2. Danail Vasilev
    Admin
    Danail Vasilev avatar
    1494 posts

    Posted 30 Jun Link to this post

    Hi Peng,

    Could you please provide us with a fully runnable sample that contains the model, view and controller pages, so that we can run it and examine the issue locally? You can create some dummy data source for the purpose or use some of our online demos that can be downloaded and run offline.

    Regards,
    Danail Vasilev
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top