SivaRajini
SivaRajini

Reputation: 7375

window.location or window.location.href not changing the value in all browsers MVC application

Current Url is

http://xx.com/Home/Employee

i have cancel button in my page whenvever cancel button clicked need to navigate from different action result which is located in aother folder

Ex: About/Result (i.e. http://xx.com/About/Result) i have below code in my cancel function

function cancel() {

        window.location = '@Url.Action("Result", "About")';

        return false;
    }

tried all the ways like

window.location.href= "/About/Result"
window.location.pathname="/About/Result"

but it still not changing the old value.it keeps old value only.

referred so many links like

window.location.href does not change the URL

https://developer.mozilla.org/en-US/docs/Web/API/Window.location

but when i try to give

 window.location.href="http://www.google.com"

it works fine. why i can't navigate from on action to another action from different directory. any problem ?

what is the exact root cause ?

Upvotes: 1

Views: 7214

Answers (1)

SivaRajini
SivaRajini

Reputation: 7375

found the solution by referring the following link

windows.location.href not working on Firefox3

need to add return like

<button id="btnCancel" class="btn" onclick="return cancel()">

in your markup for the page, the control that calls this function on click must return this function's value.

function cancel() {
        window.location.href = "../../About/Index";
        return false;
    }

Upvotes: 3

Related Questions