ToDataSourceResult Error

3 posts, 1 answers
  1. Christos
    Christos avatar
    5 posts
    Member since:
    Feb 2012

    Posted 10 Oct 2013 Link to this post

    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. Answer
    Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2192 posts

    Posted 14 Oct 2013 Link to this post

    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!
  3. Christos
    Christos avatar
    5 posts
    Member since:
    Feb 2012

    Posted 16 Oct 2013 Link to this post

    Thanks!
Back to Top