我有一个使用以下行编辑客户端的视图:
@Html.DisplayFor(x=>x.Orders)
在里面。但它只输出 Id 属性的显示,忽略其他属性:
public class Order
{
public int Id { get; set; }
[DisplayName("Order Header")]
public string Header { get; set; }
// ... etc...
}
而我希望行为是:
如果对象包含多个属性,则该方法会为每个属性生成一个字符串,该字符串由属性名称的标记和属性值的标记组成。MSDN
我错过了什么?
风景:
@model Models.Client
@{
ViewBag.Title = "Client Details";
}
<h2>@ViewBag.Title</h2>
<fieldset>
@Html.DisplayFor(x => x.Notes, "ListOfNotes")
</fieldset>
<fieldset>
@{ Html.RenderPartial("NewNoteForm", Model); }
</fieldset>
<fieldset>
@using(@Html.BeginForm())
{
@Html.EditorForModel()
<input type="submit" value="Save"/>
}
</fieldset>
<fieldset>
@Html.DisplayFor(x => x.Orders) @* The errant bit *@
</fieldset>
<fieldset>
@{ Html.RenderPartial("NewOrderForm", Model); }
</fieldset>
客户端模型:
public class Client
{
public Client(int PId, string title, string forename, string surname)
: this()
{
PId = pId;
Title = title;
Forename = forename;
Surname = surname;
}
public Client()
{
Notes = new List<Note>();
Orders= new List<Order>();
}
public int PId { get; set; }
public string Title { get; set; }
public string Forename { get; set; }
public string Surname { get; set; }
public List<Note> Notes { get; private set; }
public List<Order> Orders { get; private set; }
}
顺便说一句,笔记列表按预期显示。