我目前正在ASP.NET MVC中創建一個網站,我想使用EditorTemplates在我的ViewModel中顯示List。 RowViewModel具有RowDataViewModel的列表。我試圖爲RowViewModel創建視圖,我可以使用未使用ASP.NET MVC EditorTemplate
@Html.EditorFor(model => model.RowData)
因此我需要一個EditorTemplate。我創建並EditorTemplate下:
Views/Shared/EditorTemplates/RowDataViewModel.cshtml
,我也試圖把EditorTemplates文件夾/主頁/視圖文件夾下,但似乎沒有任何工作。 editortemplate內沒有任何斷點。我想我以前就是這樣做的,但我可能會忘記一些事情。
任何想法?
RowViewModel:
public class RowViewModel
{
[Required]
[Display(Name="Name")]
public string Name { get; set; }
public List<RowDataViewModel> RowData { get; set; }
}
RowDataViewModel:
public class RowDataViewModel
{
public string Name { get; set; }
public string Value { get; set; }
public string DataType { get; set; }
}
EditorTemplate - RowDataViewModel.cshtml:
@using iDealWebRole.ViewModels
@model RowDataViewModel
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Value, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Value, "", new { @class = "text-danger" })
</div>
</div>
你的意思'@ Html.EditorFor(型號=> model.RowData)'(不'@ model.EditorFor(...)' )? –
只是在我的帖子中輸入錯誤。現在糾正它:) –
你在這裏顯示的代碼是好的,並將正常工作。必須有其他一些問題。 –