[英]how to redirect from one controller to another with object and send response back to original view in mvc4?
i have a view login.cshtml
in my web_application and two controller Controller_1
and Controller_2
. 我在我的
login.cshtml
和两个控制器Controller_1
和Controller_2
查看了login.cshtml
。 Request generated form view contains some object of Person
class. 请求生成的表单视图包含
Person
类的一些对象。 Initially request is passed to some method User_Login
of Controller_1. 最初请求被传递给Controller_1的某个方法
User_Login
。 now i want to redirect the request from Controller_1 to some method method new_method
in Controller_2 with the Person object and it should send response back to login.chtml page. 现在我想将Controller_1中的请求重定向到带有Person对象的Controller_2中的某个方法
new_method
,它应该将响应发送回login.chtml页面。 please suggest me something... 请给我一些建议......
You can use RedirectToAction
method in User_Login
of Controller1
and redirect to action in Controller2
. 您可以在
Controller1
User_Login
中使用RedirectToAction
方法,并重定向到Controller2
。 In your action in Controller2
you can specify the desired view. 在
Controller2
的操作中,您可以指定所需的视图。
Lets say the instance of Person you get in action of Controller1
is person
. 让我们说你在
Controller1
中行动的人的实例是person
。
RedirectToAction("ActioninController2","Controller2", person);
Hope this helps! 希望这可以帮助!
You can use RedirectToAction("ActionName","ControllerName")
. 您可以使用
RedirectToAction("ActionName","ControllerName")
。 Person Object you can pass in TempData["someName"] = YourPersonObject
and in your second controller/action get: 您可以在
TempData["someName"] = YourPersonObject
传递的Person对象,在第二个控制器/动作中获取:
var person = TempData["someName"];
Last job to do is generate View for example: 最后一项工作是生成View,例如:
return View("pathToView");
or PartialView 或PartialView
return PartialView("PathToView");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.