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

ToDataSourceResult Error

2 Answers 1325 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Christos
Top achievements
Rank 1
Christos asked on 11 Oct 2013, 12:14 AM
Hello -

I had to change my Model to include two lists so i can bind it to two sets.

Now my model looks like:
public class PaymentsViewModel
{
    public List<CorporateViewModel> Corporations { get; set; }
    public List<PaymentViewModel> Payments { get; set; }
}
My controller looks like
public ActionResult Payments_Read([DataSourceRequest]DataSourceRequest request)
{
    //get corps
    //get payments
 
    PaymentsViewModel returnObj = new PaymentsViewModel();
    returnObj.Corporations = corps;
    returnObj.Payments = payments;
 
    DataSourceResult result = returnObj.ToDataSourceResult(request); <== returns error
 
    return Json(result);
}

Errors:
  • cannot convert from 'PaymentsViewModel' to 'System.Data.DataTable' 
  • 'PaymentsViewModel' does not contain a definition for 'ToDataSourceResult' and the best extension method overload 'Kendo.Mvc.Extensions.QueryableExtensions.ToDataSourceResult(System.Data.DataTable, Kendo.Mvc.UI.DataSourceRequest)' has some invalid arguments 
Any  ideas how to go about it? Should I change my ViewModel? Or have different approach?

Thanks.

2 Answers, 1 is accepted

Sort by
0
Accepted
Vladimir Iliev
Telerik team
answered on 14 Oct 2013, 09:10 AM
Hi Christos,

 
Please find the answers of your questions below:

  • cannot convert from 'PaymentsViewModel' to 'System.Data.DataTable' - It seems that you are trying to convert single record to DataTable, however you should include that model into an IEnumerable collection to be able to create a DataTable . Also please note that converting models to DataTable is not directly related to KendoUI but is a general programming task. More information on the matter can be found on various resources over the internet. For example you can check this article. 
  • 'PaymentsViewModel' does not contain a definition for 'ToDataSourceResult' and the best extension method overload 'Kendo.Mvc.Extensions.QueryableExtensions.ToDataSourceResult(System.Data.DataTable, Kendo.Mvc.UI.DataSourceRequest)' has some invalid arguments - from the provided information it seems that you are trying to use the extension method on single record, however it requires IQueriable collection. I would suggest try to wrap the model in List collection as demonstrated below:  
    DataSourceResult result = new List<PaymentsViewModel>() { returnObj }.ToDataSourceResult(request);
     
    return Json(result);
         
Regards,
Vladimir Iliev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Christos
Top achievements
Rank 1
answered on 16 Oct 2013, 01:10 PM
Thanks!
Tags
Grid
Asked by
Christos
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Christos
Top achievements
Rank 1
Share this question
or