Is there a smarter way to show/hide elements conditionally (with razor) than this below? The view is very large and I’m concerned about maintenance:
@if(@Model.Atendimento.PrazosEEntregas.Visivel)
{
<div>
<h4>Prazos e entrega do serviço</h4>
@if (!string.IsNullOrWhiteSpace(@Model.Atendimento.PrazosEEntregas.PrazoFinalizacaoServico))
{
<p>@Model.Atendimento.PrazosEEntregas.PrazoFinalizacaoServico</p>
}
@if (!string.IsNullOrWhiteSpace(@Model.Atendimento.PrazosEEntregas.PrazoRetiradaDocumento))
{
<p><strong>Prazo de retirar o documento:</strong> @Model.Atendimento.PrazosEEntregas.PrazoRetiradaDocumento</p>
}
@if (!string.IsNullOrWhiteSpace(@Model.Atendimento.PrazosEEntregas.OndeRetirarServico))
{
<p><strong>Onde retirar/receber:</strong> @Model.Atendimento.PrazosEEntregas.OndeRetirarServico</p>
}
@if (!string.IsNullOrWhiteSpace(@Model.Atendimento.PrazosEEntregas.ObservacaoPrazoRetirada))
{
<p><strong>Observação:</strong> @Model.Atendimento.PrazosEEntregas.ObservacaoPrazoRetirada</p>
}
</div>
}
Thanks,
Hoisel
You could write a custom helper that will conditionally output the contents:
and then:
Another possibility is to use a display template:
Then you could define a display template for the string type (or a custom one):
and on your view model: