次のエラーが表示されます。辞書にはエラータイプのモデルアイテムが必要です
辞書に渡さモデル項目タイプ「System.Collections.Generic.List`1 [MYAPP.Models.User]」であるが、これ 辞書タイプ 「にSystem.Collectionsのモデル項目が必要.Generic.IEnumerable`1 [MYAPP.Models.ViewModel.AccountViewModel] '。次のように
私のコードは次のとおりです。
のViewModel
public class AccountViewModel
{
...
public IQueryable<User> user { get; set; }
}
CONTROLLER
public class UserController : Controller
{
private REc db = new REc();
// GET: /User/
public ActionResult Index()
{
AccountViewModel avm = new AccountViewModel();
var users = db.Users.Include(u => u.USERROLE);
avm.user = users;
return View((avm.user).ToList());
}
VIEW
@model IEnumerable<SNAPAPP.Models.ViewModel.AccountViewModel>
@{
ViewBag.Title = "Index";
}
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.USERROLE)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.USERROLE)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.ID }) |
@Html.ActionLink("Details", "Details", new { id=item.ID }) |
@Html.ActionLink("Delete", "Delete", new { id=item.ID })
</td>
</tr>
}
</table>