javascript - MVC C# Redirect() 到字符串 url 不起作用

标签 javascript c# asp.net-mvc asp.net-mvc-4 model-view-controller

我正在尝试从必须从我的方法重定向的 URL 中检索 token 。它适用于另一种方法,但不适用于此方法。 任何帮助将不胜感激!

Controller 方法:

[HttpPost]
    public ActionResult Authorize(int clientId)
    {
        Session["client_Id"] = clientId;

        var client = GoogleAnalyticsHelper.CreateGoogleAnalyticsClient();

        string url = client.AuthorizeUrl();
        return Redirect(url);
    }

JavaScript:

function UpdateClient() {
var baseurl = "/GoogleAnalytics/";
var list = document.getElementById("clientId");
var clientId = list.options[list.selectedIndex].value;

$.ajax({
    type: "POST",
    async: false,
    url: baseurl + "Authorize",
    data: { "clientId": clientId },
    success: function () {
        console.log("success!");
    },
    error: function (er) {
        console.log("an error occured: " + er);
    }
});

};

按钮:

<button type="submit" onclick="UpdateClient()" name="button1" class="btn btn-info">Update client/ViewId</button>

最佳答案

我找到了解决方案,问题出在 Google Chrome 上。我成功的解决方案:

 success: function (url) {
        setTimeout(function () {
            window.location.assign(url);
        }, 0);
    },

关于javascript - MVC C# Redirect() 到字符串 url 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53066738/

相关文章:

c# - 查找 ASP.Net 超时原因(在长时间操作期间)

c# - ZipArchive 返回空文件 c#

asp.net-mvc - 加密后仍可读取FormsAuthenticationTicket用户数据(带有表单Auth。的ASP.NET MVC3)

c# - 当从 View (Ajax)发送请求时,即使我使用 [FromBody] C#, Controller 中也收​​到 NULL 对象

c# - 发送一个填充特殊字符的字节数组

json - 带有选项字段的 F# 记录在 Asp.Net WebApi 2.x 应用程序中未正确反序列化

javascript - 无法使用 dataTable jquery 删除表中新添加的行

javascript - 尝试在 React Native 中组织模块时无法解析模块

div层中的Javascript按钮定位帮助

javascript - 如果所选文本是 HTML,如何使用 javascript 获取所选 DOM?