This is a migrated thread and some comments may be shown as answers.

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

1 Answer 63 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Peng
Top achievements
Rank 1
Peng asked on 28 Jun 2016, 09:29 PM

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

1 Answer, 1 is accepted

Sort by
0
Danail Vasilev
Telerik team
answered on 30 Jun 2016, 10:51 AM
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
Tags
Grid
Asked by
Peng
Top achievements
Rank 1
Answers by
Danail Vasilev
Telerik team
Share this question
or