In my model class I have a boolean property DoNotEmail.
In the UI design I’ve been given to create a view for, the meaning of the checkbox is inverted; i.e. the label next to the checkbox says "Send Email".
Normally I would add the checkbox like this: @Html.CheckBoxFor(model => model.DoNotEmail) but clearly this is the wrong way round.
Do I need to create a separate view model with a custom property for this checkbox, or is there some clever way I can do something like: @Html.CheckBoxFor(model => !model.DoNotEmail) (which clearly doesn’t work)?
Passing entities directly to your view is never a good idea, if your DB schema ever changes you would have to go through all your views and update them. I would recommend creating a
ViewModeland passing only the data required for the view, then map yourDoNotEmailproperty in the controller. That way you maintain the abstraction between your model/view and keeps your view simple e.g.View
Controller