Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have the following issue: I make a jQuery ajax post and, on success, I need to change the location of the browser to an Index view. This is the javascript:

$.post(CreateReleaseNotificationURL, Notifications_Form.serialize(), function (response) {
            if (response.indexOf("Error") == 0) {
                $("#NewNotification_CreateStatus").html(response);
            }
            else {
                window.location.assign('@Url.Action("Index")');
                //window.location = window.location;                   
            }              
        })
        .fail(function () {                
            $("#NewNotification_CreateStatus").html("An error has occured.<br /> Please contact the system administrator<br /> if the problem persists.");
        });

However, nothing happens !! What am I missing ?

PS: I also tried using location.href, to no avail.

share|improve this question
    
Is the control coming inside your conditional checks ? –  harsha Aug 13 '13 at 10:34
1  
Did u tried like window.location.href = "/app/Controller/Method_name" ? –  vinothini Aug 13 '13 at 10:36
    
@harsha, what control are you talking about ? –  Octavian Epure Aug 13 '13 at 10:36
    
@vinothini, I don't want to use magic strings, I only want to use Url helper and such, since in production the magic string will most likely not work –  Octavian Epure Aug 13 '13 at 10:38
1  
If this is inside a .js file it won't work as it's not rendered. Otherwise, two debug phases. First check the HTML source to see what's @Url.Action("Index") been rendered to, second phase of debug is making sure you reached that line at all by adding alert("..."); –  Shadow Wizard Aug 13 '13 at 10:39
show 3 more comments

1 Answer

up vote 0 down vote accepted

check this:

window.location.href = '@Url.Action("Index", "ControllerName")';
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.