2

In my jquery code, I can open a new action using the following code:

window.open("ControllerAction");

However, this opens the controller action in a different tab. How can I make this open in the same window without creating a separate tab.

This is basically a workaround I have found to doing page refresh in asp.net mvc.

1
  • 1
    You should use window.location.href = "/{controller}/{action}"; Commented Dec 29, 2016 at 12:14

2 Answers 2

4

You need to use 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'

Basically you can use one of these, assign() and replace() navigates to the URL without adding a new record to the history. Here you find more: Window.location

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

instead

window.open("ControllerAction");
Sign up to request clarification or add additional context in comments.

Comments

0

Thanks for anyone who searched but I got it to work. Below code works.

window.location.replace("ControllerAction");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.