1

Scaffolding Option を使用してSubscriptionController.
以下にいくつかのコード スニペットを示します。

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; }

ここに私の質問があります:

  1. これは次のように、1 つのIDではなく LISTModelバインドされていると思いました。SubscriptionSubscription

    @foreach (モデル内の変数項目)

    これは正しいです?

  2. 1 が正しい場合、この行の理由:

    @Html.DisplayNameFor(model => model.Amount)

    モデルはAmount?これは、モデルが単一の「サブスクリプション」にバインドされていることを示唆しています。

  3. この行の場合:

    @Html.DisplayFor(modelItem => item.Amount) modelItem と item は何にバインドされていますか? ラムダがmodelItemを受け入れるのに使用しないのはなぜですか?

Model、model、および modelitem がバインドされているものを正確に説明してください。
ありがとう。

4

1 に答える 1