Conditional Column

Oct 22, 2015 at 1:06 AM
Is it possible to show only a checkbox if a value is false?

For example, I am showing a checkbox if a person is an Admin role, but I also want to add the logic to show the checkbox on that row if the d.reconciled property is == true. How can I access the current record's property in if logic?

if (User.IsInRole("Admin")) {

                    .RenderValueAs(d => Html.CheckBox("checked", new { @value = d.voucherID }));
Nov 20, 2015 at 8:25 PM
Edited Nov 20, 2015 at 8:26 PM
You can probably do this with a helper.

I have a helper like this:
@helper CurrencyCode(string db, decimal price)
    switch (db)
        case "PERU":
            <strong>S/. @price</strong>
            <strong>$ @price</strong>

This takes a string for a DB and a price and sends back the price with a dollar sign in all other cases except PERU which uses "S/."
My grid has this:
  .RenderValueAs(o => HtmlHelpers.CurrencyCode(o.DbName, o.TotalPriceLocal));
Am pretty sure you can use the above method to render a checkbox or not. My helper file seems happy to have Html.Checkbox in it.