【发布时间】:2019-09-26 04:53:42
【问题描述】:
我有一个要求,我需要将用户从 MVC Action 方法重定向到另一个外部 URL,并且还需要将某些数据发布到外部 URL。请提出可能的选项。
谢谢
【问题讨论】:
-
在视图中使用 ajax 发布外部请求,然后重定向到内部操作
-
你能分享任何参考链接吗
标签: asp.net-mvc
我有一个要求,我需要将用户从 MVC Action 方法重定向到另一个外部 URL,并且还需要将某些数据发布到外部 URL。请提出可能的选项。
谢谢
【问题讨论】:
标签: asp.net-mvc
你可以试试这样的
$(function(){
// button handle the action where you want to post data and redirect
$("#btnSubmit").click(function(){
//ajax post to internal action
$.ajax({
type: "POST",
url: '@Url.Action("ActionName","Controller"),
data: json_object_to_post,
success: function (result) {
// handle the result here if required
}
});
//redirect to the external action
window.location.href = "external_url";
});
【讨论】:
考虑有两个动作:
public ActionResult First()
{
//here store the data wither in session or tempdata
//session["data"]=postdata;
//temp["data"]=postdata
return RedirectToAction(“Second”,”ControllerName”);
}
public ActionResult Second()
{
//check for the session or temp variables
return View();
}
通过这种方式,您可以将数据从一个网址传递到另一个网址
【讨论】: