Click here to Skip to main content
15,919,423 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Everyone,,,,,,,,,,,
I am new to MVC..........
i need to create a viewmodel that holds list of objects and rendered to view......

ex:
C#
public class ResultViewModel
    {
        public List<Users> users { get; set; }
    }
public class Users
    {
        public int UserID { get; set; }
        public string UserName { get; set; }
        public string Email { get; set; }
        public DateTime Date { get; set; }
        public int DeptID { get; set; }
    }



i have a list of users in a list..... how can i assign that list to ResultViewmodel and how can i display that list in view.......
please help me........
Posted

1 solution

Try like this..

in you controller

SQL
public ActionResult Index()
{
ResultViewModel oResultViewModel=new ResultViewModel();
//list allusers and add to oResultViewModel
return View(oResultViewModel);
}


in view

C#
in view


@model ResultViewModel

foreach(var item in Model)
{
@item.UserName ,@item.Email, ...
}
 
Share this answer
 
Comments
[no name] 31-Oct-12 1:54am    
it's not working........ i think my viewmodel is wrong.. how can i create the viewmodel that holds the list of users

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900