繁体   English   中英

如何刷新 JavaScript 中的页面并使用参数重定向到控制器的 Action 方法

[英]How to Refresh a page in JavaScript and redirect to controller's Action method with parameters

我一直在尝试在 JavaScript 中使用参数将页面重新加载到特定控制器的操作方法,但出现错误。

我的 output 在我使用时工作

function fnReload(){
    window.location.reload(true);
}

但我想用 PARAM 的值重定向到控制器的操作方法,我正在尝试这个

 function fnReload(){
    // Gives me the value in a function
    var supId = data.supplierId;
    //redirects the page so the I can see the updated the data
    window.location.reload= '@Url.Action("GetSupplier", "Supplier", new { supplierId = supId })';
}

但它也对我不起作用,因为它给了我错误,并且在服务器端应用断点时它没有 go 在那里。

有人可以指导我该怎么做重新加载页面并重定向到控制器的操作方法。

提前致谢。

您可以使用 AJAX 调用此

// AJAX call
$.ajax({
    url: "GetSupplier",
    type: "get",
    data: { 
        supplierId: supId,
    },
    success: function(result) {
        result = JSON.parse(JSON.stringify(result));
        console.log(result);
        window.location = "/GetSupplier";
    },
    error: function(result) {
        result = JSON.parse(JSON.stringify(result));
        console.log(result);
    }
});

暂无
暂无

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

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