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

i have a viewmodel like this...........

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 Controller is

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()
            };

            return RedirectToAction("ServiceOrderManagerResult", "Login",resultmodel);
        }

        public virtual ActionResult ServiceOrderManagerResult(ResultViewModel model)
        {
            List<ResultViewModel> lst = new List<ResultViewModel>();
            lst.Add(model);
            return View(lst);
        }



when i am passing the model to the second action ....... the model goes to nill.......
how can i pass the model to another action.......
Posted

1 solution

Hi ,
You can use TempData for this purpose ,TempData will survive only a single redirect and be automatically evicted on the subsequent request whereas Session will be persistent across all HTTP requests for the session.

you can use also pass using query string but it is may create problem in your case as you are pissing list of data and query string has limited data


refer:
tempdata
tempdata

http://stackoverflow.com/questions/6543678/is-it-possible-to-redirect-to-another-action-passing-it-as-well-our-current-mode[^]
 
Share this answer
 

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