title: MVC 4 WebGrid Checkbox in a column with Condition
body: <p>I'm trying to add a new column to a .Net MVC WebGrid that includes a checkbox that is there if a specific condition is met and not there if the condition is false. </p>
  
  <p>The below code works to correctly display X or Y (placeholder):</p>
  
  <pre><code>        grid.Column("ID", header: "", 
              style: "labelcolumn",
              format: (item) =&gt; item.ID != null ? "X" : "Y"),
  </code></pre>
  
  <p>I can't seem to get the syntax right to include the checkbox instead of X.  </p>
  
  <pre><code>        grid.Column("ID", header: "", 
              style: "labelcolumn",
              format: (item) =&gt; item.ID != null ? @&lt;text&gt;&lt;input class="check-box" id="cbSelectedBranch" name="cbSelectedBranch" type="checkbox" value="@item.ID" /&gt;&lt;/text&gt; : "Y"),
  </code></pre>
  
  <p>On this second snippet, the "(item)" variable causes this error:</p>
  
  <blockquote>
    <p>CS0136: A local variable named 'item' cannot be declared in this scope
    because it would give a different meaning to 'item', which is already
    used in a 'parent or current' scope to denote something else</p>
  </blockquote>
  
  <p>Adding the @ when using the if null condition seems to cause item to throw this error. The below code, without the conditional, works correctly:</p>
  
  <pre><code>        grid.Column(header: "", 
              style: "labelcolumn",
              format: @&lt;text&gt;&lt;input class="check-box" id="cbSelectedBranch" name="cbSelectedBranch" type="checkbox" value="@item.ID" /&gt;&lt;/text&gt;),
  </code></pre>
  
  <p>Any idea how I can make this work with a conditional and checkbox input? </p>