Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7798969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:09:27+00:00 2026-06-02T00:09:27+00:00

In an ASP.NET MVC3 Application I have a button in the view. When the

  • 0

In an ASP.NET MVC3 Application I have a button in the view.

When the button is clicked a function is called and it jquery ajax call is made to save items to the database

    function SaveMenuItems() {
        var encodeditems = $.toJSON(ids);;
        $.ajax({
            type: 'POST',
            url: '@Url.Action("SaveItems", "Store")',
            data: 'items=' + encodeditems + '&storeKey=@Model.StoreID',
            complete: function () {
                    }
                }
            });
        }

What i want is after the items are saved to the database I want to redirect to another view. (Redirect to action)

How can I do that?

I tried to use return RedirectToAction("Stores","Store") in the controller at the end of the SaveItems function. But it is not working

I also tried to add window.location.replace("/Store/Stores"); in the complete function of the ajax call but didn’t work either

Any help is greatly appreciated

Thanks a lot

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T00:09:30+00:00Added an answer on June 2, 2026 at 12:09 am

    You can use javascript to redirect to the new page. Set the value of window.location.href to the new url in your ajax call’s success/complete event.

    var saveUrl = '@Url.Action("SaveItems","Store")';
    var newUrl= '@Url.Action("Stores","Store")';
    
    $.ajax({
        type: 'POST',
        url: saveUrl,
        // Some params omitted 
        success: function(res) {
            window.location.href = newUrl;
        },
        error: function() {
            alert('The worst error happened!');
        }
    });
    

    Or in the done event

    $.ajax({      
        url: someVariableWhichStoresTheValidUrl
    }).done(function (r) {
         window.location.href = '@Url.Action("Stores","Store")';
    });
    

    The above code is using the Url.Action helper method to build the correct relative url to the action method. If your javascript code is inside an external javascript file, you should build the url to the app root and pass that to your script/code inside external js files and use that to build the url to the action methods as explained in this post.

    Passing parameters ?

    If you want to pass some querystring parameters to the new url, you can use this overload of the Url.Action method which accepts routevalues as well to build the url with the querystring.

    var newUrl = '@Url.Action("Stores","Store", new { productId=2, categoryId=5 })';
    

    where 2 and 5 can be replaced with some other real values.

    Since this is an html helper method, It will work in your razor view only,not in external js files. If your code is inside external js file, you need to manually build the url querystring parameters.

    Generating the new url at server side

    It is always a good idea to make use of the mvc helper methods to generate the correct urls to the action method. From your action method, you can return a json strucutre which has a property for the new url to be redirected.

    You can use the UrlHelper class inside a controller to do this.

    [HttpPost]
    public ActionResult Step8(CreateUser model)
    {
      //to do : Save
       var urlBuilder = new UrlHelper(Request.RequestContext);
       var url = urlBuilder.Action("Stores", "Store");
       return Json(new { status = "success", redirectUrl = url });            
    }
    

    Now in your ajax call’s success/done callback, simply check the return value and redirect as needed.

    .done(function(result){
       if(result.status==="success")
       {
          window.location.href=result.redirectUrl;
       }
       else
       {
          // show the error message to user
       }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET MVC3 application in C# and Razor. In the view MyView
I have a Razor view in my asp.net MVC3 application with a dropdownlist like
I have a ASP.NET MVC3 application that handles time-consuming processes (copying a large file
I am creating an ASP.NET MVC3 application using NHIBERNATE. I have a base class
This is about asp.net mvc3 web application. We have used Object cache to store
I have created a web application using ASP.NET MVC3 in Visual studio (no SQL
I have an ASP.NET MVC 3 application which has a post action called Create
I have an ASP.NET MVC 3 application. This application requests records through jQuery. jQuery
I am working on an asp.net MVC 3 application. I have a C# function
I am working on asp.net MVC 3 application. I have created a Razor view

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.