Convert value to display in table - mvc Asp-net.core

Asked

Viewed 31 times

2

I have a table that brings me a value in int and I need to convert this value to time, as I can perform this procedure, in case I would need to create a function to show me the correct value.

<td>
  @Html.DisplayFor(modelItem => item.HoraInicio)
</td>

In this part I need to get the value item.HoraInicio and perform a conversion, but it does not let me declare variables to carry out the change, as I can do?

  • I use page-Razor, the created own views.

  • Yes, I managed to change other values using if, but I thought of something like @(int value), but it does not recognize.

  • Save the entire time to the bank?

1 answer

1


One option is to open a code block, it would look like this:

<td>
    @{ 
        var horario = item.HoraInicio;
        //logica
    }
    <label>@horario</label>
</td>

Another option is to have a field in your template that already brings the information as you wish

public class Horario
{
    public int HoraInicio { get; set; }

    public string HoraExibicao
    {
        get
        {
            //Logica
            return HoraInicio.ToString();
        }
    }
}

and on your page

<td>
  @Html.DisplayFor(modelItem => item.HoraExibicao)
</td>
  • 1

    My logic was right, the problem was where I was opening the code block. Thanks again. I did the same informed me and it worked.

Browser other questions tagged

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