vVvegetable
vVvegetable

Reputation: 29

how to change display format in MVC view

This is the part of the code in MVC view file cshtml. The iD is an integer number. It displays like 1 22 333, how can I make the display to 000001 000022 000333.

@foreach (var item in Model)
{
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.iD)
        </td>
    </tr>
}

Upvotes: 2

Views: 330

Answers (1)

hardkoded
hardkoded

Reputation: 21617

You don't need the DisplayForuse the model

@foreach (var item in Model)
{
  <tr>
     <td>
        @item.iD.ToString("000000")
     </td>
  </tr>
}

Upvotes: 1

Related Questions