如何使用存储过程绑定剑道网格的数据源



首先,这是我第一次使用剑道UI。在工作中,我从数据库中获得了一些数据,我想将我的 mvc 网络网格替换为令人印象深刻的剑道网格。我已经从数据库创建了一个列表,我正在尝试绑定到kento网格中。通过调用存储过程设置数据源后。网格仍然保持空。控制器:

public ActionResult index()
        {
            return View();
        }  
public JsonResult Getuser([DataSourceRequest] DataSourceRequest request)
        {
            TestDB_Emp db = new TestDB_Emp();
            var employees = db.sps_selectemp();
            DataSourceResult response = employees.ToDataSourceResult(request);
            return Json(response, JsonRequestBehavior.AllowGet);
        }

视图

@(Html.Kendo().Grid<webkendo.sps_selectemp_Result>()
        .Name("grid")
        .Columns(columns =>
        {
            columns.Bound(c => c.FirstName);
            columns.Bound(c => c.SecondName);
            columns.Bound(c => c.Email);
            columns.Bound(c => c.Gender).Width(150);
        })
        .HtmlAttributes(new { style = "height: 550px;" })
        .Scrollable()
        .Groupable()
        .Sortable()
        .Pageable()
            .DataSource(dataSource => dataSource
            .Ajax()
            .Read(read => read.Action("Getuser", "Home"))
            .PageSize(20)
        )
)

.class

namespace webkendo
{
    using System;
    public partial class sps_selectemp_Result
    {
        public string City { get; set; }
        public string FirstName { get; set; }
        public string SecondName { get; set; }
        public string Gender { get; set; }
        public string Email { get; set; }
        public string Mobile { get; set; }
        public int EmpID { get; set; }
        public Nullable<System.DateTime> DOB { get; set; }
    }
}

我的代码上缺少什么。

使用存储过程时尝试不使用实体模型。

public ActionResult Results([DataSourceRequest] DataSourceRequest request)
        {
            var page = request.Page;
            var pagesize = request.PageSize;
            SqlConnection sqcon = new SqlConnection(conn);
            SqlCommand cmd = new SqlCommand();
            SqlDataAdapter sd = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            cmd.Connection = sqcon;
            cmd.CommandText = "sps_selectemp";
            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            sqcon.Open();
            sd.Fill(dt);
            sqcon.Close();
            List<EmployeeDetails> StudentList = new List<EmployeeDetails>();
            foreach (DataRow dr in dt.Rows)
            {
                EmployeeDetails st = new EmployeeDetails();
                st.ID = Convert.ToInt32(dr["EmpID"]);
                st.FirstName = dr["FirstName"].ToString();
                st.SecondName = dr["SecondName"].ToString();
                st.Email = dr["Email"].ToString();
                st.Gender = dr["Gender"].ToString();
                st.Mobile = dr["Mobile"].ToString();
                st.City = dr["City"].ToString();

                StudentList.Add(st);
            }
            DataSourceResult response = StudentList.ToDataSourceResult(request);
            return Json(response, JsonRequestBehavior.AllowGet);
        }

最新更新