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

2

I have a table that returns me a value in int and I need to convert this value to time, how can I 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 item.HoraInicio value and perform a conversion, but it does not let me declare variables to perform the change, how can I do it?

    
asked by anonymous 05.06.2018 / 22:27

1 answer

1

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

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

Another option is to have a field in your model 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>
    
05.06.2018 / 22:35