[英]mvc3 View checking a boolean c#
I was wondering how I could do this Boolean check. 我想知道如何进行布尔检查。 I'm not very good with mvc3 Views... 我对mvc3视图不是很好...
Error 1 Cannot convert lambda expression to type 'bool' because it is not a delegate type 错误1无法将lambda表达式转换为类型'bool',因为它不是委托类型
@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.active
is a boolean, you can simply do: 由于model.active
是布尔值,因此您可以简单地执行以下操作:
@if (Model.active)
When dealing with boolean types, you never need to compare them to true
or false
. 处理布尔类型时,您无需将它们与true
或false
进行比较。
Your confusion may arise from HTML helpers taking a lambda - an if
cannot take a lambda. 您的困惑可能源于HTML帮助程序使用lambda- if
不能使用lambda。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.