ユーザーの詳細と、User と UserDetails という 2 つの異なるモデルからの拡張ユーザーの詳細を含むビュー モデルがあります。
私の UsersController には、 Details メソッドに次のものがあります-
public ViewResult Details(RegisterViewModel viewModel)
{
User currentuser = context.Users
.Include("UserDetails")
.Where(i => i.UserName == viewModel.UserName)
.First();
currentuser.UserDetails = new UserDetails();
return View(currentuser);
}
私の詳細ビューでは、次から始めます -
@model TRS.ViewModels.RegisterViewModel
次に、ビューモデルから詳細をリストしようとします。
<tr>
<td>User Name</td>
<td>@Model.UserName</td>
</tr>
しかし、ユーザーの詳細ページに移動すると、このエラーが発生します-
Server Error in '/' Application.
Sequence contains no elements
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Sequence contains no elements
Source Error:
Line 37: {
Line 38:
Line 39: User currentuser = context.Users
Line 40: .Include("UserDetails")
Line 41: .Where(i => i.UserName == viewModel.UserName)
私は明らかに何か間違ったことをしていますが、何を見つけることができませんでした。何か案は?