1

我正在尝试Grid在我的 ASP.NET MVC 应用程序中实现 KendoUI 控件。我知道 KendoUI 的人已经给出了很多例子,但它对我不起作用。

我的型号代码是:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data.Sql;
using System.Data;

namespace KendoGrid.Models
{
    public class status
    {
        public string SiteId { get; set; }
        public string SiteName { get; set; }
        public string SiteStatus { get; set; }

        public static List<status> StatusInfo()
        {    
            SqlConnection sconn = new SqlConnection(@"Data Source=DS-7071BC8FDEE6\SQLEXPRESS;Initial Catalog=AmanoTest;User ID=sa;Password=india@123");
            SqlCommand cmd = new SqlCommand("select * from SiteMaster", sconn);
            SqlDataAdapter sda = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            sda.Fill(dt);
            status cstat;
            List<status> statlist = new List<status>();
            foreach (DataRow dr1 in dt.Rows)
            {
                cstat = new status();
                cstat.SiteId = dr1[0].ToString();
                cstat.SiteName = dr1[1].ToString();
                cstat.SiteStatus = dr1[2].ToString();

                statlist.Add(cstat);    
            }
            return statlist;
        }
    }
}

我的控制器代码是:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using KendoGrid.Models;
using Kendo.Mvc.UI;

namespace KendoGrid.Controllers
{
    public class statusController : Controller
    {
        //
        // GET: /status/

        public ActionResult Index()
        {
            return View();
        }
        public ActionResult Site()
        {
            //List<status> status = status.GetStatus();
            List<status> temp = status.StatusInfo();
            ViewData["table"] = temp;
            return View();
        }    
    }
}

我的观点(.cshtml 页面)是:

@model KendoGrid.Models.status
@using Kendo.Mvc.UI 

@*@{
    Layout = null;
 }
*@
<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Site</title>
</head>
<body>
    <div>
        @(Html.Kendo().Grid(Model)()
                .Name("Grid")
                .Columns(columns =>
                    {
                        columns.Bound(p => p.siteID);
                        columns.Bound(p => p.siteID);
                        columns.Bound(p => p.siteID);
                    })
            .Pageable()
            .Sortable()
            .Scrollable()
            .Filterable() 
            .DataSource(dataSource => dataSource        
        .Ajax()
        .ServerOperation(false)
        )
     )
   </div>
</body>
</html>

在执行它说:

'Kendo.Mvc.UI.Fluent.WidgetFactory.Grid(System.Data.DataTable)' 的最佳重载方法匹配有一些无效参数

4

2 回答 2

1

看起来你在这里错过了几步。请完成此步骤,这可能会解决您的问题

http://docs.kendoui.c​​om/getting-started/using-kendo-with/aspnet-mvc/helpers/grid/ajax-binding

于 2012-10-30T14:05:57.400 回答
0

您可以使用

var url = "/DesktopModules/MyServices/API/ATSManageClient/GetAllProjectsTechnologyBased?PortalId=210&tabid=95&Technology=" + selectedplatform;

var element = $("#grid").kendoGrid({
//debugger;
    type: "odata",
    dataSource: {
        transport: {
            read: url
        },
        schema: {
            model: {
                fields: {
                    RecievedDate: { type: "date" }
                }
            }
        },
        pageSize: 100
    },

    columnMenu: true,
    scrollable: true,
    filterable: true,
    resizable: true,
    sortable: true,
    detailTemplate: kendo.template($("#template").html()),
    detailInit: detailInit,
    dataBound: function () {
    },
    columns: [
{
    field: "ProjectID",
    title: "Action",
    template: "<a href='/Dashboard/Communication?ProjectID=#=ProjectID#'>View Communication</a>",
    width: "20%"
},
//s debugger;
 {
     field: "ClientName",
     width: "20%",
     title: "Client",
     template: "<a href='Accounts/UpdateClient.aspx?ClientId=#=ClientID#'> #= ClientName #</a>",
     attributes: {
         title: "#=ClientName#"
     }
 },
  {
      field: "ProjectTitle",
      width: "20%",
      title: "Project",
      template: "<a href='Project/EditProject.aspx?ProjectID=#=ProjectID#'> #= ProjectTitle #</a>",
      attributes: {
          title: "#=ProjectTitle#"
      }
  },
        {
            field: "ColorList",
            width: "20%",
            template: kendo.template($("#template2").html()),
            title: "Status"
        },
        {
            field: "RecievedDate",
            width: "20%",
            title: "Check List Status",
            template: ""
        },
        {
            field: "RecievedDate",
            width: "20%",
            title: "Opened Bugs",
            template: ""
        }

    ],
    pageable: {
        // we don't set any DataSource here
        pageSizes: [100, 150, 200]
    }
});
于 2013-12-16T07:20:48.413 回答