I've identified several of my views that require some simple logic, for example to add a class to a set of controls created with @Html helpers. I've tried several different ways, but they either throw errors in the View or just don't work.
A simple example:
Assign variable:
@if( condition ) { var _disabled = "disabled"; } @Html.CheckBoxFor(m => m.Test, new { @class = "form-control " + @_disabled }) Or:
@if( condition ) { var _checked = "checked"; } @Html.CheckBoxFor(m => m.Test, new { @checked = @_checked }) Of course, these doesn't work. I'm just trying to eliminate a bunch of @if conditions in my Views, but I have other lightweight logic uses for using variables. My problem might be more of how to use a variable in this way than actually assigning it?