title: How to get a value of <#= Id #> when passed to a helper method
body: <p>I am using <code>ASP.NET MVC 3</code> with <code>razor</code>.  I am also using the latest version of <code>Telerik MVC</code>.</p>
  
  <p>I have a grid on my view displaying a list of applications.  Each application has a state.  I need to write a helper method to display links in each row of the grid depending on each application's current state.  If the state is 1 then I need to display an Edit link.  The helper that I have looks like this:</p>
  
  <pre><code>public static string ActionLinks(this HtmlHelper helper, string grantApplicationId, string grantApplicationStateId)
  {
       List&lt;TagBuilder&gt; linkList = new List&lt;TagBuilder&gt;();
       string actionLinks = string.Empty;
  
       if (grantApplicationStateId == "1")
       {
            // Edit link
            TagBuilder editLink = new TagBuilder("a");
            editLink.MergeAttribute("href", "/GrantApplication/Edit/" + grantApplicationId);
            editLink.InnerHtml = "Edit";
            linkList.Add(editLink);
       }
  
       foreach (TagBuilder link in linkList)
       {
            actionLinks += link.ToString() + "&lt;br&gt;";
       }
  
       return actionLinks;
  }
  </code></pre>
  
  <p>The grid column in my Telerik grid looks like this:</p>
  
  <pre><code>column.Bound(x =&gt; x.Id)
       .ClientTemplate(@Html.ActionLinks("&lt;#= Id #&gt;", "&lt;#= GrantApplicationStateType.Id #&gt;"))
       .Title("Actions");
  </code></pre>
  
  <p>My view model looks like:</p>
  
  <pre><code>public class GrantApplicationListViewModel
  {
       // Just partial properties
       public GrantApplicationStateType GrantApplicationStateType { get; set; }
  }
  </code></pre>
  
  <p>And GrantApplicationStateType looks like:</p>
  
  <pre><code>public class GrantApplicationStateType : IEntity
  {
       public int Id { get; set; }
       public string Name { get; set; }
  }
  </code></pre>
  
  <p>When the above helper method is called then the value of grantApplicationStateId is "&lt;#= GrantApplicationStateType.Id #>".  How would I get the value that was passed through?  What I mean is, if the value is 1 that was passed through, how would I get 1 because currently it is "&lt;#= GrantApplicationStateType.Id #>"?</p>
  
  <p><strong>UPDATE 2012-02-06</strong></p>
  
  <p>I tried Darin's link, used the exact same sample in my code, but changed the following:</p>
  
  <pre><code>column.ActionLink("Open", "Edit", "GrantApplication", item =&gt; new { id = item.Id, applicationStateId = item.GrantApplicationStateType.Id });
  </code></pre>
  
  <p>I need to pass through 2 values.  I need to do a couple of if statements on the grant application state id, and then return the specific action links to the client.  But it fails when looping through the values in:</p>
  
  <pre><code>if (memberExpression.Expression is ParameterExpression)
       value = string.Format("&lt;#= {0} #&gt;", memberExpression.Member.Name);
  else
       value = GetValue(memberExpression);
  </code></pre>
  
  <p>The first parameter passed in goes through the first/true part of the if statement:</p>
  
  <pre><code>value = string.Format("&lt;#= {0} #&gt;", memberExpression.Member.Name);
  </code></pre>
  
  <p>..but the second parameter goes through the false part of the if:</p>
  
  <pre><code>value = GetValue(memberExpression);
  </code></pre>
  
  <p>What's the difference between the 2?</p>
  
  <p>And then it fails at the GetValue method with the following message:</p>
  
  <pre><code>variable 'item' of type MyProject.ViewModels.GrantApplicationListViewModel' referenced from scope '', but it is not defined
  </code></pre>
  
  <p>I can't get this to work, and I looked for some more samples and couldn't find any.</p>