4
有誰知道爲什麼我收到此錯誤:
The model item passed into the dictionary is of type
system.Data.Entity.DynamicProxies.Object_3E186F803589BF82895B10E08C
2A9AB68EFA619599418D6EB96585D14874CDC0',
but this dictionary requires a model item of type
'System.Collections.Generic.IEnumerable`1[MyApplication.Domain.Entities.Object]'.
這裏是我的代碼:傳遞到字典的模型項的類型爲「System.Data.Entity.DynamicProxies.Object
控制器:
public ViewResult Index()
{
if (User.Identity.IsAuthenticated)
{
MembershipUser currentUser = Membership.GetUser();
Guid currentUserId = (Guid)currentUser.ProviderUserKey;
if (currentUser != null && currentUser.ProviderUserKey != null && currentUser.IsApproved)
{
Move result = (from move in db.Moves
where move.UserId == currentUserId
select move).FirstOrDefault();
return View(result);
}
}
return View(db.Moves.ToList());
}
查看:
@model IEnumerable<MovinMyStuff.Domain.Entities.Move>
@{
ViewBag.Title = "Index";
}
@foreach (var item in Model)
{
<div id="move-list-item">
<ul>
<li>
<span class="move-name">
@Html.DisplayFor(modelItem => item.StartCity)
@Html.DisplayFor(modelItem => item.StartState)
@Html.DisplayFor(modelItem => item.StartZip) -
@Html.DisplayFor(modelItem => item.EndCity)
@Html.DisplayFor(modelItem => item.EndState)
@Html.DisplayFor(modelItem => item.EndZip)
</span>
</li>
<li>@Html.ActionLink("Details", "Details", new { id = item.MoveId }, new { @class = "button" })</li>
</ul>
</div>
}
我得到這個錯誤,當我加入。取(1) - 錯誤無法隱式轉換鍵入'System.Linq.IQueryable'到'MovinMyStuff.Domain.Entities.Move'。存在明確的轉換(您是否缺少演員?) –
而不是.Take(1)我會執行.TakeWhile()嗎? –
而不是採取(1)我將如何採取儘可能多的用戶已創建? –