C
C#2y ago
RobW95

Html.DisplayName cutting off text

I am using ASP Net Core with .NET 6. I am trying to display data into an HTML table.
item.ToString()
"79.4%"
@Html.DisplayName(item.ToString())
"4%"
item.ToString()
"79.4%"
@Html.DisplayName(item.ToString())
"4%"
Can anyone explain why the text is getting cut off in the above snippet?
1 Reply
RobW95
RobW95OP2y ago
Surrounding code:
@model IndexModel
@{
ViewData["Title"] = "Home page";
}
<table>
<thead>
<tr>
@foreach (DataColumn column in Model._dataTable.Columns)
{
<td>
@Html.DisplayName(column.ColumnName)
</td>
}
</tr>
</thead>
<tbody>

@foreach (DataRow row in Model._dataTable.Rows)
{
<tr>
@foreach (var item in row.ItemArray){
<td>
@Html.DisplayName(item.ToString())
</td>
}
</tr>
}
</tbody>
</table>
@model IndexModel
@{
ViewData["Title"] = "Home page";
}
<table>
<thead>
<tr>
@foreach (DataColumn column in Model._dataTable.Columns)
{
<td>
@Html.DisplayName(column.ColumnName)
</td>
}
</tr>
</thead>
<tbody>

@foreach (DataRow row in Model._dataTable.Rows)
{
<tr>
@foreach (var item in row.ItemArray){
<td>
@Html.DisplayName(item.ToString())
</td>
}
</tr>
}
</tbody>
</table>
Changing to @Html.Label("", item.ToString()) fixed it
Want results from more Discord servers?
Add your server