带参数的KendoGrid下拉列表

时间:2013-01-15 08:33:13

标签: kendo-ui master-detail kendo-grid

我使用MVC,Entities和KendoGrids构建了一个主细节,我遇到了问题。

我必须从“master”KendoGrid(Tickets)中获取CustomerID,以便在“detail”(TicketsDetails)中检索CustomerContact下拉列表。

我对如何编写这样的东西很困惑

提前Thanx!

编辑:这是代码

    @(Html.Kendo().Grid<ModelApp.Models.Tickets>()
.Name("ticketgrid")
.Columns(columns =>
    {

        columns.Bound(p => p.TicketID).Title("ID").Width(100);
        columns.ForeignKey(p => p.CustomerID, (System.Collections.IEnumerable)ViewData["customers"], "CustomerID", "CustomerName").Title("Customer").Width(200) ;
        columns.ForeignKey(p => p.AreaOfBusinessID, (System.Collections.IEnumerable)ViewData["areaofbusinesses"], "AreaOfBusinessID", "AreaOfBusiness1").Title("AreaOfBusiness").Width(100);
        columns.Bound(p => p.OccurredOn).Title("Occured").Format("{0:yyyy-MM-dd}").Width(150);
        columns.ForeignKey(p => p.SeverityID, (System.Collections.IEnumerable)ViewData["severities"], "SeverityID", "Severity1").Title("Severity").Width(100);
        columns.ForeignKey(p => p.AssigneeID, (System.Collections.IEnumerable)ViewData["assignees"], "AssigneeID", "AssigneeName").Title("Assignee").Width(100);
        columns.ForeignKey(p => p.TicketStatusID, (System.Collections.IEnumerable)ViewData["ticketstatuses"], "TicketStatusID", "TicketStatus1").Title("Status").Width(100);
        columns.Bound(p => p.UserID).Title("User").Width(100);
        columns.Bound(p => p.DateRegistered).Title("Registered").Format("{0:yyyy-MM-dd}").Width(150);
})
    .ClientDetailTemplateId("ticketdetailTemplate")
.DataSource(dataSource => 
    dataSource
.Ajax()
    //.Filter(filter => filter.Add(e => e.CustomerID).IsEqualTo(CustomerID))
.Model
(model=>{
    model.Id(p => p.TicketID);
    model.Field(p=>p.TicketID).Editable(false);
    model.Field(p => p.CustomerID );
    model.Field(p => p.AreaOfBusinessID );
    model.Field(p => p.OccurredOn );
    model.Field(p => p.SeverityID );
    model.Field(p => p.AssigneeID );
    model.Field(p => p.TicketStatusID );
    model.Field(p => p.UserID );
    model.Field(p => p.DateRegistered );

})
.Read(read => read.Action("Index","Ticket"))
.Create(create => create.Action("Create", "Ticket"))
.Update(update => update.Action("Edit", "Ticket"))
//.Destroy(destroy => destroy.Action("Delete", "Ticket"))        
        )
        .Pageable()
        .Navigatable()
        .Selectable()
        .Sortable()
        .Editable(editing => editing.Mode(GridEditMode.InCell))
        .ToolBar(toolbar =>
        {
            toolbar.Create();
            toolbar.Save();
        })


 )

详细

<script id="ticketdetailTemplate"  type="text/kendo-tmpl">
@(Html.Kendo().Grid<ModelApp.Models.TicketsDetails>()
        .Name("ticketdetailgrid")
        .Columns(columns =>
        {
            columns.Bound(o => o.TicketsDetailID).Title("ID").Width(100);
            columns.Bound(o => o.TicketID ).Title("Ticket").Width(100);

            columns.ForeignKey(o => o.CustomerContactID, (System.Collections.IEnumerable)ViewData["customercontacts"], "CustomerContactID", "CustomerContactName").Title("CustomerContact").Width(150) ;
            columns.ForeignKey(o => o.TicketsDetailsViaID, (System.Collections.IEnumerable)ViewData["ticketsdetailsvia"], "TicketsDetailsViaID", "TicketsDetailsVia1").Title("Via").Width(100) ;

            columns.Bound(o => o.TicketsDetailsDesciption).Title("Description").Width(300);
            columns.Bound(o => o.TicketsdetailsNotes).Title("Notes").Width(200);
            columns.Bound(o => o.UserID).Title("User").Width(100);
            columns.Bound(o => o.DateTimeStart).Format("{0:yyyy-MM-dd}").Title("Start").Width(150);
            columns.Bound(o => o.DateTimeFinish).Format("{0:yyyy-MM-dd}").Title("Finish").Width(150);
            columns.Bound(o => o.DateRegistered).Format("{0:yyyy-MM-dd}").Title("Registered").Width(150);

        })
        .DataSource(dataSource => dataSource
            .Ajax()
            .Model
            (model =>
            {
                model.Id(q => q.TicketsDetailID);
                model.Field(q => q.TicketsDetailID).Editable(false);
                model.Field(q => q.TicketID);
                model.Field(q => q.TicketsDetailsDesciption);
                model.Field(q => q.TicketsdetailsNotes);
                model.Field(q => q.UserID);
                model.Field(q => q.DateTimeStart);
                model.Field(q => q.DateTimeFinish);
                model.Field(q => q.DateRegistered);


            })
            .Read(read => read.Action("TicketsDetailsRead", "Ticket", new { ticketID = "#=TicketID#" }))
            .Update(update => update.Action("TicketsDetailsEdit", "Ticket"))
        )
        .Pageable()
        .Sortable()
        .Editable(editing => editing.Mode(GridEditMode.InCell))
    .ToolBar(toolbar =>
    {
        toolbar.Create();
        toolbar.Save();
    })
            .ToClientTemplate()
)

和CustomerContacts的实体

 public partial class CustomerContacts
{
    public decimal CustomerContactID { get; set; }
    public decimal CustomerID { get; set; }
    public string CustomerContactName { get; set; }
    public string CustomerContactPhone { get; set; }
    public Nullable<int> CustomerContactDuty { get; set; }
}

我想从主服务器获取CustomerID的值,并使用它来检索详细信息中的CustomerContactID下拉列表

columns.ForeignKey(o => o.CustomerContactID, (System.Collections.IEnumerable)ViewData["customercontacts"], "CustomerContactID", "CustomerContactName").Title("CustomerContact").Width(150) ;

1 个答案:

答案 0 :(得分:1)

请分享一些代码。目前尚不清楚您尝试了什么,以及您需要哪个masterID。基本上,您需要使用ClientExpression(例如#=#)或 dataItem 方法作为父网格。