【发布时间】:2013-06-26 16:06:17
【问题描述】:
我使用脚手架选项创建了一个SubscriptionController。
下面是一些sn-ps的代码:
In Controller:
public ActionResult Index()
{
var subscriptions = db.Subscriptions;
return View(subscriptions.ToList());
}
In View:
@model IEnumerable<Liquidity.Domain.Entity.Subscription>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table>
<tr>
<th>
@Html.DisplayNameFor(model => model.Amount)
</th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Amount)
</td>
</td>
</tr>
}
</table>
For my subscription model, I have:
public decimal Amount { get; set; }
这是我的问题:
-
我认为
Model绑定到一个Subscription的LIST,而不是一个Subscription身份,因为这表明:@foreach(模型中的变量项)
这是正确的吗?
-
如果1是正确的,为什么在这一行:
@Html.DisplayNameFor(model => model.Amount)模型会有
Amount?这表明模型绑定到单个“订阅”。 -
对于这一行:
@Html.DisplayFor(modelItem => item.Amount)modelItem 和 item 绑定到什么?为什么 lambda 接受 modelItem 但不使用它?
请解释 Model、model 和 modelitem 到底绑定到什么。
谢谢。
【问题讨论】:
标签: asp.net-mvc razor view model