How to pass multiple objects using RedirectToAction() in Asp.NET MVC? -


i pass multiple objects using redirecttoaction() method. below actionresult i'm redirecting to.

public actionresult getemployees(models.department department, models.category category, models.role role)         {    return view(); } 

i'd below

public actionresult test() { models.department dep = new models.department(); models.category cat.......etc  return redirecttoaction("getemployees", dep, cat, role); } 

any appreciated - thanks

updated

can use

 models.department dep = new models.department() { depid = employee.departmentid };                     models.category cat = new models.category() { catid = employee.jobcategoryid };                     models.role title = new models.role() { roleid = employee.jobtitleid };              return redirecttoaction("getemployees", new { department = dep, category = cat, role = title }); 

you cannot pass objects redirecttoaction method. method designed pass parameters. need pass values want emitted in corresponding request:

return redirecttoaction("getemployees", new  {     depid = dep.depid,     depname = dep.depname,     catid = cat.catid,     roleid = role.roleid,     ... on each property need }); 

but better way send ids of objects:

return redirecttoaction("getemployees", new  {     depid = dep.depid,     catid = cat.catid,     roleid = role.roleid }); 

and in target controller action use ids retrieve entities underlying datasore:

public actionresult getemployees(int depid, int catid, int roleid) {     var dep = repository.getdep(depid);     var cat = repository.getcat(catid);     var role = repository.getrole(roleid);     ... } 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -