views:

27

answers:

1

I have a view model -

public class MyViewModel
{
   public int id{get;set;};
   Public SomeClass obj{get;set;};
}
public class SomeClass
{
   public int phone{get;set;};
   public int zip{get;set;};
}

So on my controller when I post back MyViewModel it has all the values for all the fields...but when I do

return RedirectoAction("SomeAction",vm);//where vm->MyViewModel object that has all values...

it loses the values for SomeClass object?...can anyone please help me out

+1  A: 

The second argument to RedirectToAction is route values, not a view model.

So if you do:

return RedirectoAction("SomeAction", new {Foo = "Bar"});

Then, with the default model binding, you'll redirect to this URI:

http://site/ControllerName/SomeAction?Foo=Bar

Remember how a redirect works over the wire. You can't pass a model. You can only change the URI.

Craig Stuntz
hmm..so in this example i tried doing-........ return RedirectoAction("SomeAction",new {vm=vm}) and also.......return RedirectoAction("SomeAction",new MyViewModel{idvm.id,obj= new SomeClass {phone=vm.phone,zip=vm.zip} ) but didnt work ?
Misnomer
I'm going to say this again, slowly: The second argument to `RedirectToAction` **is not a view model.** It changes the URI. **That is all.**
Craig Stuntz
got it...you could have said "tempdata" slowly..:)
Misnomer