This is a migrated thread and some comments may be shown as answers.

ClientTemplate using Ajax

5 Answers 412 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kai
Top achievements
Rank 1
Kai asked on 21 Aug 2012, 07:48 PM
Would you happen to have an example of using ajax in a client template? I have the following
columns.Template(c => @Ajax.ActionLink(c.UserName.ToString(), "GetPerson", "Home", null, new AjaxOptions { UpdateTargetId = "result" }, null)).Title("Index")
           .ClientTemplate("<a href='/Admin/Admin/GetUserRoles/#=UserName#'>#=UserName#</a>");

If I change my datasource to server() it works however my paging and editing cease working. When I change my datasource back to ajax everything else works but the parm I'm trying to my ActionMethod keeps returning null. Thanks.

5 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 24 Aug 2012, 05:00 PM
Hello Kai,

This cannot be achieved with the MVC helper since it will insert invalid for the template characters. You could add the same attributes to the anchor to use an Ajax link.
Regarding sending the parameter, I am not sure what is causing the problem. The client template looks correct. Is the parameter in the action named with the default parameter name? If yes, I will need a sample project in order to investigate what exactly goes wrong.

Regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Kai
Top achievements
Rank 1
answered on 27 Aug 2012, 01:35 PM
I actually did try doing something similar to that and got a huge 'Template invalid' error.
0
Daniel
Telerik team
answered on 29 Aug 2012, 04:23 PM
Hello Kai,

The most likely reason for the error is that a "#" character is not escaped. Please check if escaping it resolves the problem e.g.

columns.Template(c=> {})
    .ClientTemplate("<a data-ajax='true' data-ajax-mode='replace' data-ajax-update='\\#result' href='" + Url.Action("GetPerson", "Home") + "'>#= UserName#</a>");
Regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Jim
Top achievements
Rank 1
answered on 01 Jul 2014, 11:08 PM
columns.Bound(d => d.CaseInstanceID).ClientTemplate("<a href='" + Url.Action("NameMatchReview", "IDD", new { caseInstanceID = ???.CaseInstanceID }) + "'>#= CaseInstanceID#</a>");

How do I supply the routeValues properly? 

I'm not sure how to access the row item, see '???' in my code above. 

I'm using an ajax grid.

Thank you,


0
Daniel
Telerik team
answered on 04 Jul 2014, 10:01 AM
Hi,

You should append the route values to the generated URL and evaluate them using template expressions as demonstrated in this documentation topic. For example:
columns.Bound(d => d.CaseInstanceID).ClientTemplate("<a href='" + Url.Action("NameMatchReview", "IDD") + "?caseInstanceID=#=CaseInstanceID#'>#= CaseInstanceID#</a>");


Regards,
Daniel
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Kai
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Kai
Top achievements
Rank 1
Jim
Top achievements
Rank 1
Share this question
or