Visual Studio 2012 Internet Aplication MVC4 C#
ERROR
System.InvalidOperationException: The model item passed into the dictionary is of type 'System.Data.Entity.Infrastructure.DbQuery
1, but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable1
My View Expects: @model IEnumerable<OG.Models.UserProfiles> this is a dataModel not ViewModel. *This View is also one generate by the UserProfiles Model when I created the Controller ( Standart Scaffolding with @Html.DisplayNameFor(model => model.Company) and later the @foreach (var item in Model) { to list data`
My Controller Attempts:
Attempt 1 Aware ( not returning list )
return View(db.UserProfiles .Include(c => c.Roles) .Where(c => c.Roles.Any(up => up.RoleName != "Administrator")) .Select(c => new { UserID = c.UserID, UserName = c.UserName, UserCount = c.Roles.Count() }));Attempt 2 Aware ( not returning list )
var model = from usr in db.UserProfiles join rls in db.UserRoles on usr.Roles equals rls.RoleId select new { UserID = usr.UserID, UserName = usr.UserName };Attempt 3 Aware ( not returning list )
var model = from usr in db.UserProfiles.Include(t => t.Roles) where usr.Roles.Any(up => up.RoleName != "Administrator") select new WebAdminUsersLookup { UserID = usr.UserID, UserName = usr.UserName };Attempt 4 Guess this isn't a "real" list, still errors
var listOfIdeas = (from x in db.UserProfiles.Include(t => t.Roles) .Where(u => u.Roles.Any(up => up.RoleName != "Administrator")) select new { UserID = x.UserID, UserName = x.UserName }).ToList();For attempts 1-3
List<UserProfiles> modelList = new List<UserProfiles>(); modelList.Add(model.ToList());
something like that and Created a Viewmodel for them
private class WebAdminUsersLookup
{
//public List<UserProfiles> Users { get; set; }
public int UserID { get; set; }
public string UserName { get; set;}
}
Websites Searched: