Click here to Skip to main content
15,793,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi every one........

i am new to MVC world.... please help me to displaying the list in a view.....

i have the controller like this.
C#
[HttpPost]
        public ActionResult ServiceOrderManager(SOMViewModel model)
        {
            DateTime date = Convert.ToDateTime(model.Date);
            List<int> items = new List<int>();
            foreach (var objItem in model.Departments)
            {
                if (objItem.IsSelected)
                {
                    //you can get the selected item id here
                    items.Add(objItem.DeptID);
                }
            }

            List<Users> us = new List<Users>();
           foreach (var item in items)
           {
               var list = from u in db.tbl_User
                          join ul in db.tbl_User_Login on u.UserID equals ul.User_ID 
                          join d in db.tbl_Departments on ul.User_ID equals d.User_id 
                          join r in db.tbl_Roles on u.Role_ID equals r.Role_ID 
                          join p in db.tbl_PreCodes on u.Pre_Code_ID equals p.Pre_Code_ID
                          join w in db.tbl_WMPages on u.WM_Page_ID equals w.WM_Page_ID 
                          where u.CreatedDate == date || d.Department_ID==item   
                          select new { u.UserID, u.Name, u.EmailID, u.CreatedDate,d.Department_ID  };
               var lst = list.ToList();
               if (lst.Count > 0)
               {
                   foreach (var i in lst)
                   {
                        Users user = new Users
                   {
                       UserID = Convert.ToInt32(lst.ElementAt(0).UserID),
                       UserName = lst.ElementAt(0).Name,
                       Email = lst.ElementAt(0).EmailID,
                       Date = Convert.ToDateTime(lst.ElementAt(0).CreatedDate),
                       DeptID = Convert.ToInt32(lst.ElementAt(0).Department_ID)
                   };
                   us.Add(user);
                   }
               }
           }

            var resultmodel=new ResultViewModel{users=us.ToList()};
         

           

            TempData["data"] = resultmodel;
            return RedirectToAction("ServiceOrderManagerResult", "Login");
        }

        public virtual ActionResult ServiceOrderManagerResult()
        {
            ResultViewModel res = (ResultViewModel)TempData["data"];
            List<ResultViewModel> lst = new List<ResultViewModel>();
            lst.Add(res);
            return View(lst);
        }


and the viewmodel is...
C#
public class ResultViewModel
   {
       public IEnumerable<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; }
   }


and finally created a view that is stronglytyped with the REsultViewModel.....
but i am not getting the users list in list view......
please help me.......
Posted
Comments
fjdiewornncalwe 31-Oct-12 9:30am    
Please show us the markup for your View as well. We need to see how you have constructed the ListView control.
[no name] 1-Nov-12 1:02am    
ya sure....... i created a strongly typed view using Scaffold template for list of Resultviewmodel....but it not showing the properties of the viewmodel......like this.....

@model IEnumerable electronicriver.viewmodels.resultviewmodel

@{
ViewBag.Title = "ServiceOrderManagerResult";
}

ServiceOrderManagerResult



<p>
@Html.ActionLink("Create New", "Create")
</p>
<table>
<tr>

<th></th>
</tr>

@foreach (var item in Model) {
<tr>

<td>
@Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
</td>
</tr>
}

</table>

can u please help me to solve this.....

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