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

[Solved] Binding List<DataRow> to MVC Grid

2 Answers 115 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Project House
Top achievements
Rank 1
Project House asked on 23 Dec 2010, 10:11 AM
Hi,

We are trying to bind List<DataRow> to MVC grid with ajax binding but unable to do so. We are getting following error;

The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[System.Data.DataRow]', but this dictionary requires a model item of type 'messagemarketer.com.ph.report.action.BounceDetailList'.


Sample.Aspx as follows;
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/ReportMaster.Master"
    Inherits="System.Web.Mvc.ViewPage<messagemarketer.com.ph.report.action.BounceDetailList>" %>
 
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Sample
</asp:Content>
 
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <%: Html.Telerik().Grid(Model.BounceList)
    .Name("GridBounceList")
    .DataBinding(db => db.Ajax().Select("_BindBounceList", "Report"))
    .Pageable(paging => paging.PageSize(20).Style(GridPagerStyles.PageInput | GridPagerStyles.Numeric).Position(GridPagerPosition.Bottom))
    .Sortable(sorting => sorting.SortMode(GridSortMode.MultipleColumn))
    .Filterable()%>
</asp:Content>

Model as follows;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using messagemarketer.com.ph.common.basedobjects;
using messagemarketer.com.domain.Service.Interface;
using messagemarketer.com.domain.Service.Reports.Bulletin.Email.ReportItems;
using messagemarketer.com.domain.Data;
using System.Data;
 
namespace messagemarketer.com.ph.report.action
{
    public class BounceDetailList : IReport
    {
        private IService _service;
        public IService Service
        {
            set { this._service = value; }
        }
 
        public Guid ActiveBulletin { get; set; }
        public DateTime? StartDate { get; set; }
        public DateTime? EndDate { get; set; }
        public String Action { get; set; }
        public String BounceType { get; set; }
        public List<DataRow> BounceList { get; set; }
        public Int32 DataCount { get; set; }
 
        public Object Run()
        {
            switch (BounceType)
            {
                case "soft":
                    if (Action == "ready")
                        BounceList = ((IBulletinService)_service).Reports.GetBulletinReports(ActiveBulletin).EmailReports.SoftBounceListInActiveData.List;
                    else if (Action == "done")
                        BounceList = ((IBulletinService)_service).Reports.GetBulletinReports(ActiveBulletin).EmailReports.SoftBounceListInPassiveData.List;
                    break;
                case "hard":
                    if (Action == "ready")
                        BounceList = ((IBulletinService)_service).Reports.GetBulletinReports(ActiveBulletin).EmailReports.HardBounceListInActiveData.List;
                    else if (Action == "done")
                        BounceList = ((IBulletinService)_service).Reports.GetBulletinReports(ActiveBulletin).EmailReports.HardBounceListInPassiveData.List;
                    break;
                default:
                    break;
            }
 
            DataCount = BounceList.Count;
            BounceType = BounceType.Substring(0, 1) + BounceType.Substring(1, BounceType.Length - 1);
            Action = (this.Action == "ready" ? "Aktif" : (this.Action == "done" ? "Pasif" : "Genel"));
            return BounceList;
        }
    }
}


An last one, Controller as follows;
[GridAction]
public ActionResult _BindBounceList(DateTime? start = null, DateTime? end = null, String bType = null)
{
    string action = (String.IsNullOrEmpty(Request.QueryString["action"]) ? string.Empty : Request.QueryString["action"]);
    ReportManager.ActiveBulletin = new Guid(Session[SessionParameters.ACTIVE_BULLETIN].ToString());
    BounceDetailList result = (BounceDetailList)ReportManager.BounceDetailList(action, bType, start, end);
    return View(new GridModel
    {
        Data = result.BounceList
    });
 
}



Any help would be greatly appreciated.

Thank you.


2 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 23 Dec 2010, 10:36 AM
Hi Onur Buyukcaglar,

 I think the error explains itself. The model specified here:

Inherits="System.Web.Mvc.ViewPage<messagemarketer.com.ph.report.action.BounceDetailList>
Is not 

System.Collections.Generic.List`1[System.Data.DataRow]

You need to change the Inherits attribute of your page.

Regards,
Atanas Korchev
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Project House
Top achievements
Rank 1
answered on 23 Dec 2010, 11:40 AM
Hi,

Thank you for your input. Actually we were looking wrong direction, but figured it out.

Regards,

Onur
Tags
Grid
Asked by
Project House
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Project House
Top achievements
Rank 1
Share this question
or