1

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 ?

Community
  • 1
  • 1
SivaRajini
  • 7,225
  • 21
  • 81
  • 128

1 Answers1

3

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;
    }
Community
  • 1
  • 1
SivaRajini
  • 7,225
  • 21
  • 81
  • 128
  • 1
    Great find! This was driving me NUTS!!! During this process I also discovered that bar failed, and yet bar worked fine. I will now cry myself to sleep upon my keyboard. – Dave Dec 01 '16 at 14:00
  • 1
    @Dave Thanks dude! I didn't realize that any value in the anchor href attribute would override whatever location you specify in your javascript. – Levi Fuller Aug 08 '17 at 20:01