如何解决控制器中Asp.net的SelectList中的筛选器值
visual studio中的先前代码是这样,它提供了所有已登录用户的下拉列表。但是,我只希望已登录的用户
ViewBag.BloodBankId = new SelectList(db.AspNetUsers,"Id","Email");
所以我尝试在这里使用
ViewBag.BloodBankId = new SelectList(db.AspNetUsers.Where(r => r.Id == User.Identity.GetUserId()),"Email");
但是在这种情况下,存在错误
System.NotSupportedException: LINQ to Entities does not recognize the method
'System.String GetUserId(System.Security.Principal.IIdentity)' method,and this method cannot be translated into a store expression.
在这行代码中:Line:29,
Line 27: @Html.LabelFor(model => model.BloodBankId,"BloodBankId",htmlAttributes: new { @class = "control-label col-md-2" })
Line 28: <div class="col-md-10">
Line 29: @Html.DropDownList("BloodBankId",null,htmlAttributes: new { @class = "form-control" })
Line 30: @Html.ValidationMessageFor(model => model.BloodBankId,"",new { @class = "text-danger" })
Line 31: </div>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。