It seems like this question has been asked and asnwered a lot on this site, but I still cannot seem to get my problem solved. I'm getting the The model item passed into the dictionary is of type 'X', but this dictionary requires a model item of type 'Y' error, even though I'm pretty sure my code is pointing to the right place and receiving the correct viewModel.
View (Index)
@model EveryNationRandburg.ViewModels.AllUsers
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Church Members</h2>
<p>@Html.ActionLink("New Member", "Register", "Account", null, new { @class = "btn btn-primary" })</p>
<table class="table table-bordered table-hover" id="kerkmembers">
<thead>
<tr>
<th>Member</th>
<th>Email</th>
<th>Contact Number</th>
</tr>
</thead>
<tbody>
@foreach (var member in Model.AlleKerkMembers)
{
<tr>
<td>@Html.ActionLink(@member.UserName, "Edit", "KerkMember", new {id = @member.Id}, null)</td>
<td>@member.Email</td>
<td>@member.PhoneNumber</td>
</tr>
}
</tbody>
</table>
@section scripts
{
<script>
$(document).ready(function (){
$("#kerkmembers").DataTable();
})
</script>
}
ViewModel
public class AllUsers
{
public List<ApplicationUser> AlleKerkMembers = new List<ApplicationUser>();
}
Account Controller
public ActionResult Index()
{
var viewModel = new AllUsers
{
AlleKerkMembers = _context.Users.ToList()
};
return View(viewModel);
}
StackTrace
InvalidOperationException: The model item passed into the dictionary is of type 'EveryNationRandburg.ViewModels.AllUsers', but this dictionary requires a model item of type 'EveryNationRandburg.ViewModels.KonnekGroepViewModel'.
What is slightly different for my problem is that whenever I try to send a viewModel to a view, I always get the error saying it is expecting item of type 'Y' (always the same one, no matter what model I declare at the top of my view)