Telerik MVC3 Razor 批量编辑网格时出现客户端模板问题

发布于 2025-01-04 08:04:28 字数 3449 浏览 1 评论 0原文

我正在使用带有 ASP.Net MVC3 Razor 视图的 Telerik MVC Batch 可编辑网格。除了使网格可编辑之外,我还尝试添加一个带有编辑链接的列(最好是可链接的图像),单击该链接将进入单个记录的编辑页面。例如 -

 @(Html.Telerik().Grid(Model)
                    .Name("BillersGrid")
                    .DataKeys(keys => keys.Add(o => o.id))
                    .ToolBar(commands =>
                    {
                        commands.Insert();
                        commands.SubmitChanges();
                    })
                    .DataBinding(databinding =>
                    {
                        databinding.Ajax()
                            .Select("SelectBatchEditing", "BillerAdmin")
                            .Update("SaveBatchEditing", "BillerAdmin", new { id =                (string)ViewData["BillerSearchString"] });
                    }
                    )
                    .Columns(columns =>
                    {
                        columns.Command(commands => commands.Delete().ButtonType(GridButtonType.BareImage)).Width(10).Title("");                        
                        columns.Bound(o => o.id).Title("Edit").ClientTemplate("<a href='/BillerAdmin/EditBiller?id=<#=id#>'>Edit</a>");
                        columns.Bound(o => o.id).Hidden(true);
                        columns.Bound(o => o.CouponBillerName).Title("Coupon Biller Name").HtmlAttributes(new { style = "white-space:nowrap;" });
                        columns.Bound(o => o.PayeeRecipient).Title("Recipient").HtmlAttributes(new { style = "white-space:nowrap;" });
                        columns.Bound(o => o.PayeeAddress1).Title("Address 1").HtmlAttributes(new { style = "white-space:nowrap;" });
                        columns.Bound(o => o.PayeeAddress2).Title("Address 2").Width(100);
                        columns.Bound(o => o.PayeeCity).Title("City").HtmlAttributes(new { style = "white-space:nowrap;" });
                        columns.Bound(o => o.State).ClientTemplate("<#= State #>");
                        columns.Bound(o => o.PayeeZip).Title("Zip").Width(50);
                        columns.Bound(o => o.PayeeZipPlusFour).Title("Zip+4").Width(50);
                        columns.Bound(o => o.Category).ClientTemplate("<#= Category #>").HtmlAttributes(new { style = "white-space:nowrap;" });
                        columns.Bound(o => o.AccountNumberFormat).Title("Account Number Format").Width(50);
                        columns.Bound(o => o.CodeLineNumberFormat).Title("CodeLine Number Format").Width(50);
                    })
                    .Pageable(paging => paging.Position(GridPagerPosition.Bottom).Style(GridPagerStyles.NextPreviousAndNumeric).Total((int)ViewData["BillersCount"]).PageSize(50))
                    .EnableCustomBinding(true)
                    .Editable(editing => editing.Mode(GridEditMode.InCell))
                    .Sortable()
                    .ClientEvents(evt => evt.OnDataBinding("BillersGrid_onDataBinding"))
                    .KeyboardNavigation(config => config.EditOnTab(true))
                    .HtmlAttributes(new { style = "font-size:.9x cem;" })
                    )

这有效。但问题是网格在第一次渲染时会显示 Id(这是一个 GUID)。在分页时,“编辑”超链接正确显示。

第一次渲染网格

有人可以帮助我吗?我希望网格每次都显示编辑链接。该单元格应该是不可编辑的,并且应该是指向另一个视图的超链接。该功能工作正常。问题是 ID 在第一次渲染时显示。 请帮忙。

谢谢, SDD

I am using a Telerik MVC Batch editable grid with ASP.Net MVC3 Razor views. In addition to having the grid to be editable I am also trying to add a column with an Edit link (ideally a linkable image), clicking on which will lead me to an edit page for the individual record. Eg -

 @(Html.Telerik().Grid(Model)
                    .Name("BillersGrid")
                    .DataKeys(keys => keys.Add(o => o.id))
                    .ToolBar(commands =>
                    {
                        commands.Insert();
                        commands.SubmitChanges();
                    })
                    .DataBinding(databinding =>
                    {
                        databinding.Ajax()
                            .Select("SelectBatchEditing", "BillerAdmin")
                            .Update("SaveBatchEditing", "BillerAdmin", new { id =                (string)ViewData["BillerSearchString"] });
                    }
                    )
                    .Columns(columns =>
                    {
                        columns.Command(commands => commands.Delete().ButtonType(GridButtonType.BareImage)).Width(10).Title("");                        
                        columns.Bound(o => o.id).Title("Edit").ClientTemplate("<a href='/BillerAdmin/EditBiller?id=<#=id#>'>Edit</a>");
                        columns.Bound(o => o.id).Hidden(true);
                        columns.Bound(o => o.CouponBillerName).Title("Coupon Biller Name").HtmlAttributes(new { style = "white-space:nowrap;" });
                        columns.Bound(o => o.PayeeRecipient).Title("Recipient").HtmlAttributes(new { style = "white-space:nowrap;" });
                        columns.Bound(o => o.PayeeAddress1).Title("Address 1").HtmlAttributes(new { style = "white-space:nowrap;" });
                        columns.Bound(o => o.PayeeAddress2).Title("Address 2").Width(100);
                        columns.Bound(o => o.PayeeCity).Title("City").HtmlAttributes(new { style = "white-space:nowrap;" });
                        columns.Bound(o => o.State).ClientTemplate("<#= State #>");
                        columns.Bound(o => o.PayeeZip).Title("Zip").Width(50);
                        columns.Bound(o => o.PayeeZipPlusFour).Title("Zip+4").Width(50);
                        columns.Bound(o => o.Category).ClientTemplate("<#= Category #>").HtmlAttributes(new { style = "white-space:nowrap;" });
                        columns.Bound(o => o.AccountNumberFormat).Title("Account Number Format").Width(50);
                        columns.Bound(o => o.CodeLineNumberFormat).Title("CodeLine Number Format").Width(50);
                    })
                    .Pageable(paging => paging.Position(GridPagerPosition.Bottom).Style(GridPagerStyles.NextPreviousAndNumeric).Total((int)ViewData["BillersCount"]).PageSize(50))
                    .EnableCustomBinding(true)
                    .Editable(editing => editing.Mode(GridEditMode.InCell))
                    .Sortable()
                    .ClientEvents(evt => evt.OnDataBinding("BillersGrid_onDataBinding"))
                    .KeyboardNavigation(config => config.EditOnTab(true))
                    .HtmlAttributes(new { style = "font-size:.9x cem;" })
                    )

This works. But the issue is that the grid is displayed with the Id (which is a guid) the first time it is rendered. On paging the "Edit" hyperlink is correctly shown.

first time grid is rendered

On going to the next page

Can some one help me. I would like the grid to show the Edit link every time. This cell should be non editable and should be a hyperlink going to another view. The functionality works correctly. The issue is the ID gets displayed the first time it is rendered.
Please help.

Thanks,
SDD

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尤怨 2025-01-11 08:04:28

客户端模板在 ajax 绑定期间应用。您的网格最初是在服务器端绑定的:

Html.Telerik().Grid(Model)

也可以设置服务器端模板:

columns.Bound(o => o.id).Title("Edit")
       .Template(@<text>
           <a href="/BillerAdmin/[email protected]">Edit</a>
        </text>) 
       .ClientTemplate("<a href='/BillerAdmin/EditBiller?id=<#=id#>'>Edit</a>");

或者使用 ajax 使网格最初绑定:

Html.Telerik().Grid<YourModelType>()

Client templates are applied during ajax binding. Your grid is initially bound server-side:

Html.Telerik().Grid(Model)

Either set a server-side template as well:

columns.Bound(o => o.id).Title("Edit")
       .Template(@<text>
           <a href="/BillerAdmin/[email protected]">Edit</a>
        </text>) 
       .ClientTemplate("<a href='/BillerAdmin/EditBiller?id=<#=id#>'>Edit</a>");

or make the grid initially bound using ajax:

Html.Telerik().Grid<YourModelType>()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文