0

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

我必须从“主”KendoGrid(Tickets)中获取 CustomerID,以便在“详细信息”(TicketsDetails)中检索 CustomerContact 下拉列表。

我对如何编写这样的事情感到困惑

提前谢谢!

编辑:这是代码

掌握

    @(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; }
}

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

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

1 回答 1

1

请分享一些代码。目前尚不清楚您尝试了什么以及您在哪里需要该 masterID。基本上,您需要使用诸如#= #之类的ClientExpression或父网格的dataItem方法。

于 2013-01-15T11:50:04.547 回答