1) I am trying to conditionally add a column into a WebGrid. And it is an anchor tag() with an img tag () inside. How can I do it?
2) The column will be displayed only if 2 parameters is not null(byte[] item.Boleto, string item.Nome_Arquivo). I set the value of both of them to null if no value is selected via sql query. Therefore, I only would need to check if both are not null, then diplay the column. But again, how do I check for it? Where can I place a conditional statement or anything like (e.g. ternary, etc) inside the WebGrid structure without ruining the rest of it?
Let me know if any translation are needed in order to understand my issue
The line I want to "translate" to WebGrid pattern:
grid.Column("", "", format: @<a href="data:application/pdf;charset=utf-8;base64,@System.Convert.ToBase64String(item.Boleto).ToString()" target="_blank" download="@item.Nome_Arquivo" type="application/pdf" rel="noopener noreferrer"><img src="@Url.Content("~/Content/images/download_arquivo.png")" alt="down" height="16" width="16" /></a>)
and here is the full grid(not necessarry, but I am giving it for clarity):
@
@{
@grid.GetHtml(
alternatingRowStyle: "linha-Alternada",
htmlAttributes: new { id = "gridListagemTituloReceber" },
fillEmptyRows: true,
columns: grid.Columns(
grid.Column("", "", format: @<a href="data:application/pdf;charset=utf-8;base64,@System.Convert.ToBase64String(item.Boleto).ToString()" target="_blank" download="@item.Nome_Arquivo" type="application/pdf" rel="noopener noreferrer"><img src="@Url.Content("~/Content/images/download_arquivo.png")" alt="down" height="16" width="16" /></a>),
grid.Column("Tipo", ModelNames.PedidoPerfilClienteAbaTituloReceberViewModel_Tipo),
grid.Column("Data_Emissao", ModelNames.PedidoPerfilClienteAbaTituloReceberViewModel_Data_Emissao,
format: (item) => item.Data_Emissao == null ? "" : String.Format("{0:dd/MM/yyyy}", item.Data_Emissao)),
grid.Column("Chave", ModelNames.PedidoPerfilClienteAbaTituloReceberViewModel_Chave),
grid.Column("Numero_Titulo", ModelNames.PedidoPerfilClienteAbaTituloReceberViewModel_Numero_Titulo),
grid.Column("Nota_Saida", ModelNames.PedidoPerfilClienteAbaTituloReceberViewModel_Nota_Saida),
grid.Column("Data_Vencimento", ModelNames.PedidoPerfilClienteAbaTituloReceberViewModel_Data_Vencimento,
format: (item) => item.Data_Vencimento == null ? "" : String.Format("{0:dd/MM/yyyy}", item.Data_Vencimento)),
grid.Column("Valor", ModelNames.PedidoPerfilClienteAbaTituloReceberViewModel_Valor,
format: (item) => item.Valor == null ? "" : String.Format("{0:N2}", item.Valor),
style: "alinhado-Direita"),
grid.Column("Data_Baixa", ModelNames.PedidoPerfilClienteAbaTituloReceberViewModel_Data_Baixa,
format: (item) => item.Data_Baixa == null ? "" : String.Format("{0:dd/MM/yyyy}", item.Data_Baixa)),
grid.Column("Valor_Recebido", ModelNames.PedidoPerfilClienteAbaTituloReceberViewModel_Valor_Recebido,
format: (item) => item.Valor_Recebido == null ? "" : String.Format("{0:N2}", item.Valor_Recebido),
style: "alinhado-Direita"),
grid.Column("Valor_Atualizado", ModelNames.PedidoPerfilClienteAbaTituloReceberViewModel_Valor_Atualizado,
format: (item) => item.Valor_Atualizado == null ? "" : String.Format("{0:N2}", item.Valor_Atualizado),
style: "alinhado-Direita"),
grid.Column("Codigo_Especie", ModelNames.PedidoPerfilClienteAbaTituloReceberViewModel_Codigo_Especie),
grid.Column("Descricao_Baixa", ModelNames.PedidoPerfilClienteAbaTituloReceberViewModel_Descricao_Baixa),
grid.Column("Data_Devolucao", ModelNames.PedidoPerfilClienteAbaTituloReceberViewModel_Data_Devolucao,
format: (item) => item.Data_Devolucao == null ? "" : String.Format("{0:dd/MM/yyyy}", item.Data_Devolucao)),
grid.Column("Motivo_Devolucao", ModelNames.PedidoPerfilClienteAbaTituloReceberViewModel_Motivo_Devolucao)
)
)
}
try
grid.Column("", "",
@<text>
@if (item.Boleto != null && item.Nome_Arquivo != null)
{
<a href="data:application/pdf;charset=utf-8;base64,@System.Convert.ToBase64String(item.Boleto).ToString()" target="_blank" download="@item.Nome_Arquivo" type="application/pdf" rel="noopener noreferrer"><img src="@Url.Content("~/Content/images/download_arquivo.png")" alt="down" height="16" width="16" /></a>
}
</text>),