Asp.net mvc 2 在asp.net mvc 2.0中重定向到操作时丢失的viewmodel内对象的值?
我有一个视图模型-Asp.net mvc 2 在asp.net mvc 2.0中重定向到操作时丢失的viewmodel内对象的值?,asp.net-mvc-2,viewmodel,redirecttoaction,Asp.net Mvc 2,Viewmodel,Redirecttoaction,我有一个视图模型- 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;}; } 所以在我的控制器上,当我回发我的ViewModel时,它拥有所有字段的所有值……但是当我回发时 return Redir
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;};
}
所以在我的控制器上,当我回发我的ViewModel时,它拥有所有字段的所有值……但是当我回发时
return RedirectoAction("SomeAction",vm);//where vm->MyViewModel object that has all values...
它丢失了SomeClass对象的值?…有人能帮我吗
因此,如果你这样做:
return RedirectoAction("SomeAction", new {Foo = "Bar"});
然后,使用默认模型绑定,您将重定向到此URI:
http://site/ControllerName/SomeAction?Foo=Bar
记住重定向是如何在线路上工作的。你不能通过模型。您只能更改URI。
因此,如果你这样做:
return RedirectoAction("SomeAction", new {Foo = "Bar"});
然后,使用默认模型绑定,您将重定向到此URI:
http://site/ControllerName/SomeAction?Foo=Bar
记住重定向是如何在线路上工作的。你不能通过模型。您只能更改URI。hmm..因此在本例中,我尝试了-。。。。。。。。返回重定向操作(“SomeAction”,new{vm=vm}),并且。。。。。。。return RedirectoAction(“SomeAction”,new MyViewModel{idvm.id,obj=new SomeClass{phone=vm.phone,zip=vm.zip})但没有起作用?我要慢慢地再说一遍:
RedirectToAction
的第二个参数不是视图模型。它改变了URI。就是这样。明白了……你可以说“tempdata”慢慢地…:)或者如果您可以绕过操作..返回视图(“SomeView”,vm)…它将传递viewmodel.hmm..所以在这个例子中我尝试了-…返回重定向操作(“SomeAction”,new{vm=vm}),还有..返回重定向操作(“SomeAction”,new MyViewModel{idvm.id,obj=new SomeClass{phone=vm.phone,zip=vm.zip})但是没用?我要慢慢地再说一遍:RedirectToAction
的第二个参数不是视图模型。它改变了URI。仅此而已。明白了…你可以慢慢地说“tempdata…”或者如果你可以绕过动作..返回视图(“SomeView”,vm)…它将传递视图模型。