I want to use a partial view to represent the rows of a table:
// SomeItem.cshtml
@model SomeItemModel
<tr>
<td>
@Html.DisplayTextFor(m => m.SomeField)
</td>
<td>
@Html.DisplayTextFor(m => m.AnotherField)
</td>
</tr>
And call it from a view representing a page containing that table:
// SomeCollection.cshtml
@model SomeCollection
...
<table><tbody>
@foreach (TipoDocumentoModel item in Model) {
Html.Partial("SomeItem", item);
}>
</tbody></table>
...
But it doesn’t work. Why?
Calling
Html.Partialreturns aMvcHtmlStringwithout writing anything to the page.You need to add an
@to render theMvcHtmlStringto the page.