asp.net-mvc-3 – Telerik MVC网格,在运行时从集合或字典中使用动态列
发布时间:2020-12-30 10:28:52  所属栏目:asp.Net  来源:互联网 
            导读:在过去几天搜索之后,我正式陷入困境.我正在研究将对象绑定到Telerik MVC 3 Grid,但问题是它需要动态创建的列(不是自动生成的).其中三列是已知的,其他列是未知的,这是棘手的部分.基本上,它可以像这些例子: KnownColumn1 | KnownColumn2 | UnknownColumn1 | Kn
                
                
                
            | 
                         在过去几天搜索之后,我正式陷入困境.我正在研究将对象绑定到Telerik MVC 3 Grid,但问题是它需要动态创建的列(不是自动生成的).其中三列是已知的,其他列是未知的,这是棘手的部分.基本上,它可以像这些例子: KnownColumn1 | KnownColumn2 | UnknownColumn1 | KnownColumn3 因为我将未知列放在列表中(我也尝试过字典,所以我可以获取列名),这在绑定时对我来说很复杂.我的代码如下: 模型(可以有零到几百行,但是这个模型在List类型的视图模型中,也可以有0到20个动态添加的列) public class VendorPaymentsGLAccount
{
    public string GeneralLedgerAccountNumber { get; set; }
    public string GeneralLedgerAccountName { get; set; }
    public string DisplayName { get { return string.Format("{0} - {1}",GeneralLedgerAccountNumber,GeneralLedgerAccountName); } }
    public Dictionary<string,double> MonthAmount { get; set; }
    public double Total { get { return MonthAmount.Sum(x => x.Value); } }
    public List<string> Columns { get; set; }
    public List<double> Amounts { get; set; }
    public VendorPaymentsGLAccount() { }
} 
 查看(注释掉的部分试图使用字典) <fieldset>
    <legend>General Ledger Account Spend History</legend>
    @if (Model.VendorPaymentsGLAccounts != null)
    {
            <br />
            @(Html.Telerik().Grid(Model.VendorPaymentsGLAccounts)
                    .Name("Grid")
                    .Columns(columns =>
                    {
                        columns.Bound(gl => gl.DisplayName).Title("General Ledger Account").Width(200).Filterable(false).Sortable(false);
                        //foreach (var month in Model.VendorPaymentsGLAccounts[0].MonthAmount)
                        //{
                        //    //columns.Bound(gl => gl.MonthAmount[month.Key.ToString()].ToString()).Title(month.Key.ToString()).Width(100).Filterable(false).Sortable(false);
                        //    //columns.Template(v => Html.ActionLink(v.VoucherID,"VoucherSummary",new { id = v.VoucherID,bu = v.BusinessUnitID,dtt = v.InvoiceDate.Ticks })).Title("Voucher").Width(100);
                        //    columns.Template(gl => Html.ActionLink(gl.MonthAmount[month.Key.ToString()].ToString(),"VoucherSummary")).Title(month.Key.ToString()).Width(100);
                        /                         | 
                  
相关内容
- ASP.NET MVC3中的HTML反而不是JSON的IIS响应
 - asp.net – 在VS Code中指定localhost端口的位置
 - asp.net-mvc – SSL安全SaaS应用程序的URL设计
 - asp.net-mvc – 如何将KendoUI DropDownListFor绑定到ViewD
 - asp.net-core – 具有取消令牌的自定义AspCore中间件
 - asp.net-mvc – 在ASP.NET身份中角色与声明的最佳实践
 - asp.net+js实现批量编码与解码的方法
 - asp.net repeater手写分页实例代码
 - asp.net – 渗透测试人员说.ASPXAUTH cookie是不安全的并且
 - asp.net – Jquery Ajax,不在Internet Explorer中工作
 
