forum

Home / DeveloperSection / Forums / How to get all users in mvc?

How to get all users in mvc?

Anonymous User331609-Oct-2014
I’m using the Membership Provider and would like to display a list of all the users and their First Name, Last Name etc using the GetAllUsers function.

I'm having trouble understanding how to implement this function in MVC.

Has anyone implemented this in MVC or is there an easier way to list all the users in my application?
Any help or advise would be really helpful.
Controller:
publicActionResult GetUsers()
        {
            var users = Membership.GetAllUsers();
            return View(users);
        }

View Model:

publicclassGetUsers
        {
            [Required]
            [DisplayName("User name")]
            publicstring UserName { get; set; }
 
            [Required]
            [DisplayName("User name")]
            publicstring FirstName { get; set; }
        }

View: 

<%= Html.Encode(item.UserName) %>

Error:

The model item passed into the dictionary is of type 'System.Web.Security.MembershipUserCollection', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[Account.Models.GetUsers]'.


Updated on 09-Oct-2014
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By