【问题标题】:kendo grid with more than one datasource具有多个数据源的剑道网格
【发布时间】:2013-07-17 07:18:11
【问题描述】:

我有 3 个单选按钮。我有 3 个不同的存储过程,为 3 个不同的单选按钮调用。 例子: 我有一个剑道网格。我希望所有 3 个单选按钮选择的结果都显示在同一个网格中。 FindCustomer_Result 是我调用客户详细信息的存储过程。 现在,如果我选择第二个单选按钮,我希望显示资源存储过程详细信息。 请帮忙。

@(Html.Kendo().Grid<proj.Data.FindCustomer_Result>()
            .Name("CustomerSearch")
            .Columns(columns =>
            {
                columns.Bound(p => p.ID).Visible(false);
                columns.Bound(p => p.FirstName).Width(130);
                columns.Bound(p => p.LastName).Width(100);
                columns.Bound(p => p.Address1).Width(150);
            })
            .DataSource(dataSource => dataSource
                .Ajax()
          //call getcustomer to fetch details of customer
         .Read(read => read.Action("GetCustomer", "Customer")
                                .Data("functiontobind"))
                .ServerOperation(false)
            )
            .Sortable()
            .Scrollable()
            .Filterable()
            .RowAction(row => row.HtmlAttributes.Add("data-id", row.DataItem.ID))
            )

【问题讨论】:

    标签: asp.net-mvc entity-framework database-design kendo-grid


    【解决方案1】:

    创建一个包含三个 RadioButtons 的 ViewModel:

    public class MyViewModel
    {
        public int Id {get;set;}
        public bool Radio1 {get;set;}
        public bool Radio2 {get;set;}
        public bool Radio3 {get;set;}
    }
    

    然后在你的Controller(Customer)中填写ViewModel并指定Action(GetCustomer)

    public class CustomerController : Controller
    {
        .......
        public ActionResult GetCustomer([DataSourceRequest] DataSourceRequest gridRequest)
        {
            IList<MyViewModel> myViewModels = new List<MyViewModel>();
            //fill ViewModels here from stored Procedures
            return Json(myViewModels.ToDataSourceResult(gridRequest));
        }
        ........
    }
    

    然后改变你的视图代码如下:

    @(Html.Kendo().Grid<MyViewModel>()
            .Name("CustomerSearch")
            .Columns(columns =>
            {
                columns.Bound(p => p.ID).Visible(false);
                columns.Bound(p => p.Radio1).Width(130);
                columns.Bound(p => p.Radio2).Width(100);
                columns.Bound(p => p.Radio3).Width(150);
            })
            .DataSource(dataSource => dataSource
                .Ajax()
          //call getcustomer to fetch details of customer
         .Read(read => read.Action("GetCustomer", "Customer")
                                .Data("functiontobind"))
                .ServerOperation(false)
            )
            .Sortable()
            .Scrollable()
            .Filterable()
            .RowAction(row => row.HtmlAttributes.Add("data-id", row.DataItem.ID))
            )
    

    【讨论】:

    • 感谢@Ping 之前的回复。我还是不明白如何为同一个网格调用三个视图,请您详细说明“”//fill ViewModels here from stored Procedures“”部分。
    猜你喜欢
    • 2014-01-04
    • 1970-01-01
    • 1970-01-01
    • 2015-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多