Supermode
Supermode

Reputation: 936

column template kendo ui grid mvc action link

The following code is working fine in development, as soon as i deploy in web server it said could find file directory. I need to change the .client template so its not hard coded like before. So if we deploy to the server where the Top folder name different or the hierarchy change, it still find the page.

I was thinking using @Url.Action but not sure how in this case to implement in .CLientTemplate

columns.Template(@<text>
           @Html.ActionLink(@item.FirstName, "Index", "Summary", new { testId = @item.FirstName })  
         </text>)
          .ClientTemplate("<a href='/Summary/Index/?testId =#= TestId #'>#=FirstName#</a>").Title("First Name");

Upvotes: 7

Views: 31048

Answers (4)

Dushantha
Dushantha

Reputation: 103

I got this one working fine

columns.Bound(a => a.Id)
       .Title("Action")
       .Filterable(false)
       .ClientTemplate(
                       "<a href='" 
                      + Url.Action("ActionName", "Controller") 
                      + "/#= Id #'" 
                      + ">View</a>"
                      );

I needed an extra column and a link button field for go to details page of a customer. I don't need filter option for this column and that is why I remove it using Filterable(false). Also you can give the link content and column header as above. This value "/#= Id #'" is the one I pass to the controller action method.

Upvotes: 6

stuart
stuart

Reputation: 215

I've seen 87 different examples of this and none of them worked. This is what I finally did and it worked, and it's simple as heck.

columns.Bound(p => p.member_id)
       .ClientTemplate("<a href='/members/details/#=member_id#'>Details</a>")
       ;

Upvotes: 0

Nasser
Nasser

Reputation: 663

In case you're using server-binding (as opposed to ajax) and Razor as your view-engine, here is an example. I need a link such as /Controller/Action/Id where Id is obtained from a property of the model. Please note that @item denotes the model instance being currently processed by the grid.

columns.Template(@<text>@Html.ActionLink(AbaScore.Resources.App.Edit,"ACTION", "CONTROLLER", new { @item.Id }, null)</text>)

Upvotes: 3

Oxon
Oxon

Reputation: 5041

Something like this should do:

.ClientTemplate("<a href='" + Url.Action("Index", "Summary", new { testId = "#=TestId#" }) + "'>#=FirstName#</a>")

Upvotes: 8

Related Questions