I’m learning MVC and I’m trying to create an implicitly typed variable for my model but not sure how to reference it in the view @model IEnumerable<???>
Controller…
public ActionResult Users() {
var model = from MembershipUser u in Membership.GetAllUsers()
select new {user = u, roles = string.Join(", ", Roles.GetRolesForUser(u.UserName))};
View(model);
}
That’s an anonymous type you’re returning. I believe you’ll want to use an actual type. If you don’t have one for what you’re selecting in your query, you’ll want to create one.
Once you have your type, here’s an example of using it in the view.
This is the first line in my view:
And I’m using it in a WebGrid: