如何在不单击Controller方法的情况下基于单击显示Webgrid列内的C#列表

问题描述 投票:0回答:1

好的,所以我现在已经将头靠在这个头上了一段时间。我具有以下Model结构:

public class MemberAddressBook
{
    [Key]
    public long MemberID { get; set; }

    [Required]
    public string EmailAddress { get; set; }

    [Required]
    [Display(Name = "Title")]
    [MaxLength(30, ErrorMessage = "Title cannot be longer than 30 characters.")]
    public string Title { get; set; }

    [Required]
    [Display(Name = "Message")]
    public string EmailMessage { get; set; } 

    [Required]
    [Display(Name = "Selected Union Member")]
    public IEnumerable<string> selectedMemberID { get; set; }

    public string LastName { get; set; }
    public string FirstName { get; set; }
    public string MemberCardNumber { get; set; }
    public IEnumerable<MemberAddressBook> selectedMemberAddress { get; set; }
}

public class GroupMessageBookList: MemberAddressBook
{
    public string Description { get; set; }
    public long? MembershipTypeID { get; set; }
    public List<GroupMessageBookList> selectedGroupsOnly { get;set; }
}

我具有从Web API填充的如下数据结构:

    groupaddressbook.selectedGroupsOnly = listgroupaddressbook
        .GroupBy(x => new { x.Description, x.MembershipTypeID })
        .Select(gcs => new GroupMessageBookList()
        {
            Description = gcs.Key.Description,
            MembershipTypeID = gcs.Key.MembershipTypeID,
            selectedMemberAddress = gcs.ToList()
            }).ToList();

上面看起来像:

enter image description here

在仔细检查特定条目后,我具有以下结构:

enter image description here

如您在第二幅图像中看到的,我有一个List,称为selectedmemberaddress,其特定条目的计数为41。 List看起来像:

enter image description here

最后,我使用View这样在WebGrid中显示此结构:

<div style="overflow: auto!important; height:300px" class="transactionGrid">
    @{
        var grid = new WebGrid(source: Model.selectedGroupsOnly, canPage: false, canSort: true);
        @grid.GetHtml(
            tableStyle: "webGrid",
            htmlAttributes: new { id = "SelectAllWebGrid" },
            headerStyle: "grid-header",
            rowStyle: "gridRow",
            mode: WebGridPagerModes.All,
            firstText: "<< First",
            previousText: " < Previous",
            nextText: "Next >",
            lastText: "Last >>",
            caption: "Group Details",
            columns: grid.Columns(
            grid.Column(
            format: @<text>
                    <input type="checkbox" value="@item.MembershipTypeID" name="childChkbox" id="checkAll" />
            </text>,
            header: "{checkall}"
            ),
            //grid.Column("Group Name/See Details", format: @<text>@Html.ActionLink((string)item.Description, "GetMemberDetailsOnGroups", "AddressBook", new { groupid = item.MembershipTypeID }, null)</text>, style: "titleColumn")
            grid.Column("Description", "Group Name")
            ))
    }
</div>

这最终将呈现此View

enter image description here

您可以看到我能够从结构中获取Key值。我的问题是,有没有一种方法可以显示selectedmemberaddress List中每个Key的关联WebGrid值。也许单击事件会显示此列表,但我不确定如何实现这一点。我不需要进行任何AJAX调用,因为我的结构中已经有分组的数据。

任何帮助将不胜感激。

谢谢

c# asp.net-mvc linq webgrid
1个回答
0
投票

对不起,我还不能发表评论,所以我将其发送到这里,我认为这可能对您有用。How to Create Nested WebGrid with Expand/Collapse in ASP.NET MVC4

© www.soinside.com 2019 - 2024. All rights reserved.