Error creating a condition in Webgrid’s Html.Raw

Asked

Viewed 172 times

0

I am trying to put a condition in a Webgrid line and the following error occurs: Cannot convert lambda expression to type 'string' because it is not delegate type
inserir a descrição da imagem aqui

Even based on this post Variable content is not displayed in the View with credits from Meajudasilvio I can’t make it work:

grid.Column(Model.DescricaoServico_002, format: (item) =>
{
    if (item.Status == 1)
    {
        return Html.Raw(@<text><div><a href="@Url.Action("ExportarPDFSelecionado", "ProcessamentoRegistros", new { idprocessamentodiario = item.IdProcessamentoDiario, idservico = item.Servico_002.Length > 0 ? item.Servico_002.Substring(item.Servico_002.Length - 3, 3) : item.Servico_002 })" target='_blank'>@(item.Servico_002.Length > 0 ? item.Servico_002.Substring(0, item.Servico_002.Length - 3) : item.Servico_002)</a></div></text>);
    }
    else
    {
        return Html.Raw("<font color='red'><b>Inativo</b></font>");
    }
}),
  • You’ve already solved it, Adriano?

  • Not yet @Aline

  • Tried to put all your if inline assigned to a variable and replace @ with a "?

  • Ah, and also, if your: item.Servico_002 is an msm string? what is its value?

  • Hi @Aline thanks so much for the suggestions I put yes the @ and the item is a string yes, but I managed to solve using the string.format. I’ll post the solution.

1 answer

0

Solved by placing the tag inside a String.format:

return Html.Raw(string.Format("<text><div><a href=\"{0}\" target='_blank'>{1}</a></div></text>", @Url.Action("ExportarPDFSelecionado", "ProcessamentoRegistros", new { idprocessamentodiario = item.IdProcessamentoDiario, idregistro = item.IdRegistro, Parametro = item.Parametro, idservico = item.Servico_002.Length > 0 ? item.Servico_002.Substring(item.Servico_002.Length - 3, 3) : item.Servico_002 }), item.Servico_002.Length > 0 ? item.Servico_002.Substring(0, item.Servico_002.Length - 3) : item.Servico_002));

Browser other questions tagged

You are not signed in. Login or sign up in order to post.