一个视图模型内对象的值丢失重定向到asp.net的MVC 2.0的动作? [英] The value for a object inside a viewmodel lost on redirect to action in asp.net mvc 2.0?

查看:118
本文介绍了一个视图模型内对象的值丢失重定向到asp.net的MVC 2.0的动作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个视图模型 -

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

所以我的控制器上,当我回来后MyViewModel它拥有的所有值的所有字段......但是当我做

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...

它失去了SomeClass的对象中的值?......任何人都可以请帮我

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

推荐答案

第二参数 RedirectToAction 是路径的值,而不是一个视图模型。

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

所以,如果你做的:

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

然后,用默认的模型绑定,你会重定向到这个网址:

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

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

记住一个重定向是如何工作的通过线路。您的无法的传递模式。你可以的只有的修改URI。

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

这篇关于一个视图模型内对象的值丢失重定向到asp.net的MVC 2.0的动作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆