私は次の見解を持っています...
@model IEnumerable<Contact>
@{ ViewBag.Title = "Contact Manager"; }
<table>
<tr>
<th>
@Html.DisplayNameFor(model => model.FirstName)
</th>
<th>
@Html.DisplayNameFor(model => model.MiddleName)
</th>
<th>
@Html.DisplayNameFor(model => model.LastName)
</th>
<th>
@Html.DisplayNameFor(model => model.HomePhone)
</th>
<th>
@Html.DisplayNameFor(model => model.WorkPhone)
</th>
<th>
@Html.DisplayNameFor(model => model.MobilePhone)
</th>
<th>
@Html.DisplayNameFor(model => model.EMail)
</th>
<th></th>
</tr>
@*This first row is the search form*@
<tr>
<th>
@Html.EditorFor(model => model.FirstName)
</th>
<th>
@Html.EditorFor(model => model.MiddleName)
</th>
<th>
@Html.EditorFor(model => model.LastName)
</th>
<th>
@Html.EditorFor(model => model.HomePhone)
</th>
<th>
@Html.EditorFor(model => model.WorkPhone)
</th>
<th>
@Html.EditorFor(model => model.MobilePhone)
</th>
<th>
@Html.EditorFor(model => model.EMail)
</th>
<th></th>
</tr>
</table>
問題は、「EditorFor()」呼び出しの述語引数の「モデル」パラメーターが、「DisplayNameFor()」メソッドのように個々の連絡先アイテムではなく、IEnumerable を参照することです。したがって、プロパティ名 (「FirstName」など) が IEnumerable のプロパティではないため、コンパイル エラーが発生します。
Intellisense は実際に、関数の述語引数で使用される「メソッド」パラメーターに対して、さまざまな IEnumerable メソッド (「Select()」など) を返します。奇妙なことに、"DisplayNameFor()" メソッド呼び出しが機能しているように見えても、Intellisense は連絡先のプロパティを表示しません。
ここの違いは何ですか?
正直なところ、モデルが IEnumerable であるため、この構文が機能しないことは理にかなっています。ただし、厳密に型指定されたビューをリストとして生成するときにウィザードによって挿入される「DisplayNameFor()」メソッドで機能する理由について混乱しています。次に、この場合、なぜ一方 (DisplayNameFor()) では機能するのに、もう一方 (EditorFor()) では機能しないのでしょうか。
ありがとう、G