简体   繁体   English

如何将模型传递给另一个区域的控制器?

[英]How to pass a model to a controller on another area?

I have a model and want to pass it to a controller on another area. 我有一个模型,并希望将其传递给另一个区域的控制器。

This is my default action but does not work: 这是我的默认操作,但不起作用:

public ActionResult defaultAction()
{
    Class1 myclass = new Class1() { name = "xxx" };

    return RedirectToAction("Index", "MemberHome", 
                             new { area = "member",model=myclass});
}

Action in another area: 在另一个领域的行动:

[HttpPost]
public ActionResult Index(Class1 c)
{
    return View();
}

You are trying to pass a complex object of type Class1 to RedirectToAction , which is done via url string, and therefore can not accept that. 您正在尝试将类型为Class1的复杂对象传递给RedirectToAction ,这是通过url字符串完成的,因此无法接受。 You could change the parameters you are sending, 你可以改变你发送的参数,

or use TempData: 或使用TempData:

TempData["class1"] = myclass;

then in your Index action retrieve it 然后在您的索引操作中检索它

Class1 c = TempData["class1"] as Class1;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM