我有以下視圖模型:爲什麼不編輯爲呈現HTML?
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; }
}
當我填寫了我的模型,並嘗試用DisplayTemplate它不顯示任何東西來顯示MatrixRows。我DisplayTemplate的名稱是MatrixRows.cshtml它放在裏面查看/共享/ DisplayTemplates
這是我用來顯示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" />
}
當我使用的RenderPartial它工作正常.. 。 我究竟做錯了什麼?
的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>
我不知道for循環的arent neccesary。 SLaKs在你面前回答,所以我必須給他提供這個觀點,因爲他的回答也是正確的。感謝您提供有用的提示! – Kenci