2013-08-17 15 views
0

我無法在Kendo Grid Client模板中獲取RouteUrl值。見下文 代碼爲某種原因,它是顯示在同一頁面,而不是去調用房源詳細信息頁面與標識我無法在Kendo網格客戶端模板中獲取RouteUrl值。請參閱下面的代碼

@(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

什麼是列模板生成的HTML輸出?查看源代碼並查找kendoGrid初始化腳本。 –

回答

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方法。它會將它們作爲字符串文字,並且可能會在返回超鏈接之前對其進行編碼。

如果你改變你的模板看起來像這樣:

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

你會在正確的軌道上,我要把它留給你的工作了休息。

+0

你說得對。我也注意到,但是在之前的版本中使用了相同的語法,這就是爲什麼我不明白爲什麼它停止工作。謝謝您的幫助。 – user2573723

相關問題