I was wondering how I could do this Boolean check. I’m not very good with mvc3 Views…
Error 1 Cannot convert lambda expression to type ‘bool’ because it is not a delegate type
@model Project.Domain.Worker //active is a value in worker
@if (model => model.active == true) { //this doesn't work
<div class="editor-label">
@Html.LabelFor(model => model.param)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.param)
@Html.ValidationMessageFor(model => model.param)
</div>
}
Since
model.activeis a boolean, you can simply do:When dealing with boolean types, you never need to compare them to
trueorfalse.Your confusion may arise from HTML helpers taking a lambda – an
ifcannot take a lambda.