0

我无法在 Kendo Grid 客户端模板中获取 RouteUrl 值。出于某种原因,请参阅下面的代码,它显示的是同一页面,而不是使用 ID 调用列表详细信息页面

@(Html.Kendo().Grid<SharedListingViewModel>()
                    .Name("listing-grid")
                    .Columns(columns =>
                    {

                        columns.Bound(x => x.Id)                           
                            .ClientTemplate("<a href='" + Url.RouteUrl("Listing", new { listingId = "#= Id #", SeName = "#= SeName #" }) + "'" + ">Show Details</a>");
  );
 columns.Command(command => { command.Destroy(); }).Width(160);

                    })
                    .Editable(x =>
                    {
                        x.Mode(Kendo.Mvc.UI.GridEditMode.InLine);
                    })
                    .Pageable()
                    .Sortable()
                    .Scrollable()
                                //.HtmlAttributes(new { style = "height:430px;" })                                   
                    .DataSource(dataSource => dataSource
                        .Ajax()
                        .Events(events => events.Error("error_handler"))
                        .Model(model => model.Id(x => x.Id))
                        .Read(read => read.Action("FavoritesList", "MemberProfile"))
                        .Destroy(destroy => destroy.Action("FavoritesDelete", "MemberProfile"))

                    )
                   )
4

1 回答 1

0

这一行是问题:

columns.Bound(x => x.Id)
    .ClientTemplate("<a href='" + Url.RouteUrl("Listing", new { listingId = "#= Id #", SeName = "#= SeName #" }) + "'" + ">Show Details</a>");

);

这样想:

var template = "<a href='{0}'>Show Details</a";
template = String.Format(template, Url.RouteUrl("Listing, new {
    listingId = "#= Id #",
    SeName = "#= SeName#"
});
columns.Bound(x => x.Id)
    .ClientTemplate(template);

你能发现问题吗?

您将 Kendo 模板字符串作为参数提供给 Url.RouteUrl 方法。它将它们作为字符串文字,并可能在返回超链接之前对它们进行 URL 编码。

如果您将模板更改为如下所示:

var template = "<a href='{0}?listingId=#= Id #&SeName=#= SeName #'>Show Details</a>";

你会走在正确的轨道上,剩下的交给你来解决。

于 2013-08-19T00:19:40.073 回答