window.location或window.location.href没有更改所有浏览器MVC应用程序中的值

时间:2014-01-17 09:18:49

标签: javascript jquery asp.net-mvc asp.net-mvc-4 window

当前网址

http://xx.com/Home/Employee

当我点击取消按钮需要从位于另一个文件夹中的不同动作结果导航时,我的页面中有取消按钮

例如:关于/结果(即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"

一切正常。为什么我无法从动作导航到不同目录中的另一个动作。有什么问题吗?

确切的根本原因是什么?

1 个答案:

答案 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;
    }