我无法在Kendo网格客户端模板中获取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"))
)
)
答案 0 :(得分: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 Template字符串作为参数提供给Url.RouteUrl方法。它将把它们作为字符串文字,并且可能在返回超链接之前对它进行URL编码。
如果您将模板更改为如下所示:
var template = "<a href='{0}?listingId=#= Id #&SeName=#= SeName #'>Show Details</a>";
你将走上正确的轨道,我会留给你去完成其余的工作。