这有效:
@if (ViewBag.SkipPhone == null)
{
<span>@Html.LabelFor(model => model.Phone)</span>
<span>@Html.TextBoxFor(model => model.Phone)</span>
<span>@Html.ValidationMessageFor(model => model.Phone)</span>
}
但我想做这样的事情:
@if (ViewBag.SkipPhone == null)
{
Html.LabelFor(model => model.Phone);
Html.TextBoxFor(model => model.Phone);
Html.ValidationMessageFor(model => model.Phone);
}
我了解 HTML 助手输出字符串,这就是第二个不起作用的原因。但是有没有合适的方法来做这种事情?