【问题标题】:Redirect to external URL in MVC5在 MVC5 中重定向到外部 URL
【发布时间】:2017-05-02 02:17:43
【问题描述】:

我需要通过单击按钮重定向到外部url。 在我看来,在一个按钮对象中,我调用myFunction() 时没有任何参数。

在控制器中,我有以下代码:

public ActionResult myFunction()
{
    return Redirect("www.google.com.ar");
}

但是,当点击按钮时,我被重定向到“http://localhost:xxxxx/myController/www.google.com.ar”。

我该如何解决这个问题?

【问题讨论】:

  • 我认为这是不可能的,如果你在客户端这样做可能是另一种选择
  • 为什么不在按钮下添加带有特定url的标签?
  • 我没有这样做,因为我必须在同一个函数中关闭我的会话(注销并清除凭据)。重定向只是函数的结尾。

标签: c# asp.net redirect button asp.net-mvc-5


【解决方案1】:

你也可以这样做:

<input type="button" id="buttonid" value="Destination" onclick="window.location.href='<%= Url.Action("actionName", "controllerName") %>';" />

或者

 return Content("<script>window.location = 'http://www.example.com';</script>");

或者

使用javascript重定向:

$( "#buttonid" ).click(function() {

 var url =  "http://www.example.com";

     location.href = url; 

});

【讨论】:

    猜你喜欢
    • 2016-03-21
    • 2017-12-11
    • 2012-01-10
    • 2012-08-02
    • 1970-01-01
    • 1970-01-01
    • 2018-06-24
    • 2011-07-02
    • 1970-01-01
    相关资源
    最近更新 更多