当前网址
当我点击取消按钮需要从位于另一个文件夹中的不同动作结果导航时,我的页面中有取消按钮
例如:关于/结果(即http://xx.com/About/Result)我的取消功能中有以下代码
function cancel() {
window.location = '@Url.Action("Result", "About")';
return false;
}
尝试了所有方式,如
window.location.href= "/About/Result"
window.location.pathname="/About/Result"
但它仍然没有更改旧值。它仅保留旧值。
引用了很多像
这样的链接window.location.href does not change the URL
https://developer.mozilla.org/en-US/docs/Web/API/Window.location
但是当我尝试给予
时 window.location.href="http://www.google.com"
一切正常。为什么我无法从动作导航到不同目录中的另一个动作。有什么问题吗?
确切的根本原因是什么?
答案 0 :(得分:3)
通过参考以下链接找到解决方案
windows.location.href not working on Firefox3
需要添加返回
<button id="btnCancel" class="btn" onclick="return cancel()">
在页面的标记中,单击时调用此函数的控件必须返回此函数的值。
function cancel() {
window.location.href = "../../About/Index";
return false;
}