とMVC 5のasp.net SelectListの、私はビューに渡していますこれはアクションコントローラ内の選択リストです条件
ViewBag.UserName = new SelectList(db.Users.Where(g => g.UserName == User.Identity.GetUserName()), "UserName", "UserName");
:
<div class="form-group">
@Html.LabelFor(model => model.UserName, "UserName", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("UserName", null, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.UserName, "", new { @class = "text-danger" })
</div>
</div>
、それはERROを働いていません。
エンティティへのLINQは方法 ' GetUserName(System.Security.Principal.IIdentity)可能System.String' メソッドを認識しない、とこの メソッドをストア式に変換することはできません。
Linq式の中で関数呼び出し「User.Identity.GetUserName()」を使用することはできません。あなたができることは、まず 'User.Identity.GetUserName()'の値を変数に代入し、その変数をlinq式で使用することです。 –