I have the following ViewModel:
public class ShowMatrixQuestionViewModel : ShowQuestionViewModel
{
public Dictionary<MatrixRows, List<MatrixColumns>> columnrow;
public List<MatrixColumns> columns;
public List<MatrixRows> rows;
public ShowMatrixQuestionViewModel()
{
columns = new List<MatrixColumns>();
rows = new List<MatrixRows>();
columnrow = new Dictionary<MatrixRows, List<MatrixColumns>>();
}
}
public class MatrixColumns
{
public int Column_ID { get; set; }
public int Column_Number { get; set; }
public String Column_Description { get; set; }
public Boolean IsAnswer { get; set; }
}
public class MatrixRows
{
public int Row_Id { get; set; }
public String Row_Number { get; set; }
public String Row_Description { get; set; }
}
When i fill up my model and try to show the MatrixRows with a DisplayTemplate it doesnt show anything. The name of my DisplayTemplate is MatrixRows.cshtml and it is placed inside Views/Shared/DisplayTemplates
This is the code i use to display a MatrixRow:
@model TestInheritance.Models.ShowMatrixQuestionViewModel
@using (Html.BeginForm())
{
<div id="edit">
<h2>Columns</h2>
@foreach (var column in Model.columns)
{
<p>@column.GetType().Name</p>
Html.RenderPartial("EditMatrixColumn", column);
}
<h2>Rows</h2>
@foreach (var rows in Model.rows)
{
<p>@rows.GetType()</p>
Html.DisplayFor(x => rows);
//Html.RenderPartial("EditMatrixRow", rows);
}
</div>
<input type="submit" value="Finished" />
}
It works fine when i used RenderPartial… What am i doing wrong?
The code for the DisplayTemplate:
@model TestInheritance.Models.MatrixRows
@using TestInheritance.Helpers
<div class="editrow">
@using (Html.BeginCollectionItem("rows"))
{
<span>
Nummer:
@Html.EditorFor(cn => Model.Row_Number)
</span>
<br />
<span>
Beskrivelse:
@Html.EditorFor(bs => Model.Row_Description)
</span>
}
</div>
Html.DisplayForreturns HTML.You aren’t doing anything with that HTML.
You probably want to write it to the page by writing
@Html.DisplayFor(...)