gpt4 book ai didi

c# - 如何使用 window.open 在 mvc 中的 jquery 中的同一窗口中打开 Controller 操作?

转载 作者:行者123 更新时间:2023-11-30 20:32:30 24 4
gpt4 key购买 nike

在我的 jquery 代码中,我可以使用以下代码打开一个新操作:

window.open("ControllerAction");

但是,这会在不同的选项卡中打开 Controller 操作。如何在不创建单独选项卡的情况下在同一窗口中打开它。

这基本上是我发现的在 asp.net mvc 中进行页面刷新的解决方法。

最佳答案

你需要使用Window.location

Though Window.location is a read-only Location object, you can also assign a DOMString to it. This means that you can work with location as if it were a string in most cases: location = 'http://www.example.com' is a synonym of location.href = 'http://www.example.com'

基本上您可以使用其中之一,assign()replace() 导航到 URL,而不向历史记录添加新记录。在这里您可以找到更多信息:Window.location

var url = "/{controller}/{action}";
window.location.href = url;
window.location.assign(url);
window.location = url;
window.location.replace =url;

代替

window.open("ControllerAction");

关于c# - 如何使用 window.open 在 mvc 中的 jquery 中的同一窗口中打开 Controller 操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41379499/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com