Variable content is not displayed in the View

Asked

Viewed 20 times

1

Instead of displaying the value of item.Endereco in Webgrid what is displayed is a text @item.Endereco.Length > 0 ? item.Endereco.Substring(0, item.Endereco.Length - 3) item: item..
In my current scenario I have to do this validation with the substring in View (on webgrid)

@grid.GetHtml(
    tableStyle: "grid",
    headerStyle: "head",
    columns: grid.Columns(
        grid.Column("Empresa", "Empresa"),
        grid.Column("Nome", format: @<text><a href="@Url.Action("Index", "Home", new { id = item.Id})">@item.Nome</a></text>),
        grid.Column("Endereco", format: @<text><a href="@Url.Action("Index", "Contato", new { id = item.Id})">@item.Endereco.Length > 0 ? item.Endereco.Substring(0, item.Endereco.Length - 3) : item.Endereco</a></text>)
    )
)

1 answer

1


When using the value of variavel in view has to put the @ otherwise shall be construed as text.

grid.Column("Endereco", format: @<text><a href="@Url.Action("Index", "Contato", new { id = item.Id})">@item.Endereco.Length > 0 ? @item.Endereco.Substring(0, @item.Endereco.Length - 3) : @item.Endereco</a></text>)

- Another possible solution:

@(item.Endereco.Length > 0 ? item.Endereco.Substring(0, item.Endereco.Length - 3) : item.Endereco)

Utilise @(codigo aqui)

- In his example:

grid.Column("Endereco", format: @<text><a href="@Url.Action("Index", "Contato", new { id = item.Id})">@(item.Endereco.Length > 0 ? item.Endereco.Substring(0, item.Endereco.Length - 3) : item.Endereco)</a></text>

  • Thanks @Meaudasilvio worked correctly, but I have another situation like this: formatting within an if condition in Html.Row here (https://answall.com/questions/212730/erro-ao-crea-umacondi%C3%A7%C3%A3o-no-html-raw-do-webgrid) I thank you.

Browser other questions tagged

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