Extending Telerik client template column and getting the values passed through


Staff member
I am using the latest version
Telerik MVC controls
. I am using

I have a grid that lists all of my grant applications. I am wanting to use a grid that loads these grant applications via AJAX. I also need to create a client template column that has action links. These action links can vary depending on the state of each grant application.

I worked through the article at: <a href="http://gedgei.wordpress.com/2011/07/02/telerik-mvc-grid-actionlink-column/" rel="nofollow">http://gedgei.wordpress.com/2011/07/02/telerik-mvc-grid-actionlink-column/</a>. I implemented the code as is and it works, I can create a client template column with a link in it. In my scenario I need to be able to pass in 2 parameters to the helper method, like:

column.ActionLink("Open", "Edit", "GrantApplication", item =&gt; new { id = item.Id, applicationStateId = item.GrantApplicationStateType.Id });

How I eventually implement this method in the end will change, but for now I am playing with these 2 input parameters to see how they are passed through and how I can retrieve them in the helper method.

The first question that I have regarding the article, why does the writer do the following:

var builder = factory.Template(x =&gt;
     var actionUrl = urlHelper.Action(action, controller, routeValues.Compile().Invoke(x));

     return string.Format(@"&lt;a href=""{0}""&gt;{1}&lt;/a&gt;", actionUrl, linkText);

I can only assume that this is the server side template that is created? But nothing displays in the grid, so how do I skip this part and go directly to the client template (this is what I actually need).

The following part is also confusing because when the first parameter (id) check comes through then it is of type
so it goes into the true part of the if, but when the second parameter (grant application state id) comes in then it is of another type (not sure what) so then it goes into the false part of the if statement:

switch (argument.NodeType)
     case ExpressionType.Constant:
          value = ((ConstantExpression)argument).Value;

     case ExpressionType.MemberAccess:
          MemberExpression memberExpression = (MemberExpression)argument;

          if (memberExpression.Expression is ParameterExpression)
               value = string.Format("&lt;#= {0} #&gt;", memberExpression.Member.Name);
               value = GetValue(memberExpression);


          throw new InvalidOperationException("Unknown expression type!");

When the second paramenter values goes into the false part of the if statement it fails here:

value = GetValue(memberExpression);

..and gives the following error message which I have no idea what it is:

variable 'item' of type MyProject.ViewModels.GrantApplicationListViewModel' referenced from scope '', but it is not defined

Here is my view model:

public class GrantApplicationListViewModel
     public int Id { get; set; }
     public string FirstName { get; set; }
     public string LastName { get; set; }
     public string FullNameDisplay
          get { return FirstName + " " + LastName; }

     public DateTime CreatedDate { get; set; }

     public GrantApplicationStateType GrantApplicationStateType { get; set; }

Here is my partial grid declaration in my view:

     .Columns(column =&gt;
          column.Bound(x =&gt; x.Id)
                    "&lt;label class=\"reference-number\"&gt;&lt;a href=\"" + @Url.RouteUrl(Url.GrantApplicationDetails("&lt;#= Id #&gt;")) + "\"&gt;" + "&lt;#= Id #&gt;" + "&lt;/a&gt;&lt;/label&gt;"
               .Title("Ref #")

          column.Bound(x =&gt; x.FullNameDisplay)

          column.Bound(x =&gt; x.GrantApplicationStateType.Name)

          //column.ActionLink("Edit", "Edit", "GrantApplication", item =&gt; new { id = item.Id });

          column.ActionLink("Open", "Edit", "GrantApplication", item =&gt; new { id = item.Id, applicationStateId = item.GrantApplicationStateType.Id });
     .DataBinding(dataBinding =&gt; dataBinding.Ajax().Select("AjaxGrantApplicationsBinding", "Home"))
     .Pageable(paging =&gt; paging.PageSize(30))
     .TableHtmlAttributes(new { @class = "telerik-grid" })

What I am trying to achieve with the above is code is something to the effect of:

if grant application id  = 1

     then return Edit link and View link


     then return Details link

How would I do the above? Is the code in that article the only way to do it? Isn't there a more simplar way? I did Google and couldn't find much help on what I want to do. Has any one else come across something like this?