title: How to get the MVC contrib grid custom colum working with aspx
body: <p>I am using the MVC Contrib Grid for rendering, sorting and filtering my data grid, but I am having problems now that it has been upgraded for MVC3 and Razor. The Custom method in my columns collection does not work for aspx pages , and the columns Action method is now obsolete.</p>
  
  <p>I use grids action method to render my columns like this in MVC 2:</p>
  
  <pre><code> ...
   &lt;% Html.Grid(Model).Columns(column =&gt; {
              column.For(x =&gt; x.Id);
              column.For(x =&gt; x.Name);
              column.For(x =&gt; x.Email);
              column.For(x =&gt; x.DateOfBirth);
              column.For("View User").Named("Tools").Action(x =&gt; { %&gt;
                   &lt;td&gt;
                     &lt;%= Html.ActionLink("View", "View", new { id = p.Id })%&gt;
                     &lt;%= Html.ActionLink("Edit ", "Edit", new { id = p.Id })%&gt;
                     //Snip as there are too many tools :-)
                     //.....
                     &lt;%= Html.ActionLink("Delete", "Delete", new { id = p.Id })%&gt;
                  &lt;/td&gt;
              &lt;% });
   ...
  </code></pre>
  
  <p>Now with the latest version there is a Custom method that replaces the obsolete Action method. I looked at how it can be done <a href="https://stackoverflow.com/questions/6391737/how-to-use-a-custom-column-in-a-mvccontrib-grid-model">in here</a>, which basically works for me now, but I loose all my helpers in the aspx view (url, etc), and now need to render my contents in another method in my model like below:</p>
  
  <pre><code> ...
   &lt;% Html.Grid(Model).Columns(column =&gt; {
              column.For(x =&gt; x.Id);
              column.For(x =&gt; x.Name);
              column.For(x =&gt; x.Email);
              column.For(x =&gt; x.DateOfBirth);
              //the new custom column 
              column.Custom(Model.ToolsRenderer);
              &lt;% });
   ...
  </code></pre>
  
  <p>The grid model method below called ToolsRenderer is used to render my html string.</p>
  
  <pre><code> public UserManagementViewModel : BaseModel {
     //..snip
     //
       public object ToolsRenderer(Client client)
       {
          List&lt;string&gt; links = new List&lt;string&gt;();
  
          var editLink = new TagBuilder("a");
          // here is my biggest problem, before  Html.ActionLink used to make
          // sure that I don't have any missing links or help me if i need to 
          // refactor an action / controller name :-(
          editLink.Attributes["href"] = GetEditUserLink(client,   HttpContext.Current.Request.Url.AbsoluteUri);
          editLink.SetInnerText("edit");
          links.Add(editLink.ToString());
          ...
          ...lots of links to be generated here
          ...
          return MvcHtmlString.Create(string.join(" |", links))
          }
     //..snip
  }
  </code></pre>
  
  <p>This works for now, but is there a way to get my aspx page working like the razor views like below?</p>
  
  <pre><code>@Html.Grid(Model).Columns(column =&gt;
  {
    column.For(x =&gt; x.Id).
    column.For(x =&gt; x.Name);
    column.Custom(@&lt;td&gt;&lt;a href='@Html.Actionlink("edit","user",new {id})' alt="@item.email"/&gt;&lt;a&gt;&lt;/td&gt;)
  
  })
  </code></pre>
  
  <p>I want to say something like:</p>
  
  <pre><code>...     
  column.Custom(%&gt;&lt;td&gt;&lt;a href='&lt;%=Html.Actionlink("edit","user",new {id})%&gt;' alt="&lt;%=item.email%&gt;"/&gt;&lt;a&gt;&lt;/td&gt;&lt;%)
  ...
  </code></pre>