Search code examples
asp.net-mvcasp.net-mvc-4telerik-gridtelerik-mvcactionlink

Ajax.Actionlink not working with Telerik MVC Grid


I realize this is an answer to my own issue but after reading this link on the meta I figured I would post this in hopes that it helps someone avoid spending hours trying to find an answer like I did.

I was trying to add an Ajax.Actionlink to a client template for MVC grid and was getting cryptic error 'Invalid template'. Finally found the issue to stem from the UpdateTargetID = "myElement". Ajax.ActionLink generates an unescaped "#" for the update target which completely breaks the grid.

I do not have the monthly plan to post to Telerik forums regarding this issue otherwise I would have.


Solution

  • My work around was:

    columns.Bound(p => p.ID).Title("myTitle")
                                .ClientTemplate(Ajax.ActionLink("View", "myAction", "myController", new { myParam = "#=ID#" }, new AjaxOptions() { OnSuccess = "myJSFunction" }).ToHtmlString());
    


    Then:

    function myJSFunction(response) {
        $("#updateTargetElement").html(response);
    }