title: MVC 3 Webgrid - how do you hide columns you do not want to be visible?
body: <p>I have a webgrid and there is a column I want to be visible only to certain users.
  Currently I have coded the grid as follows</p>
  
  <pre><code>if (Context.User.IsInRole(Role.Inputter) || Context.User.IsInRole(Role.Administrator))
  {
      @grid.GetHtml(columns: grid.Columns(
          grid.Column(format: (item) =&gt; Html.ActionLink("Select", "Details", new { contractId = item.ContractId })),
          grid.Column(format: (item) =&gt; Html.ActionLink("Edit", "Edit", new { contractId = item.ContractId })),
          grid.Column("SignOffDate", "Sign Off Date",
              format: @&lt;text&gt; &lt;span&gt;@item.SignOffDate.ToString("d/M/yyyy")&lt;/span&gt;&lt;/text&gt;),
          grid.Column("FullContractNumber", "Contract Number"),
          grid.Column("ContractTitle", "Title")
      ));
  }
  else
  { 
      @grid.GetHtml(columns: grid.Columns(
          grid.Column(format: (item) =&gt; Html.ActionLink("Select", "Details", new { contractId = item.ContractId })),
          grid.Column("SignOffDate", "Sign Off Date",
              format: @&lt;text&gt; &lt;span&gt;@item.SignOffDate.ToString("d/M/yyyy")&lt;/span&gt;&lt;/text&gt;),
          grid.Column("FullContractNumber", "Contract Number"),
          grid.Column("ContractTitle", "Title")
      ));
  }
  </code></pre>
  
  <p>But surely there is a better way without repeating all that code?
  The only difference between the 2 column inputs is that I want to display the Edit link for particlaur users. So what is the best alternative way of doing that?</p>