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

  • Home
  • SEARCH
  • 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 8398401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:02:49+00:00 2026-06-09T21:02:49+00:00

I am building a MVC3 web application and I am using knockoutjs. There are

  • 0

I am building a MVC3 web application and I am using knockoutjs. There are two views in the application. SetUpNewCompany and ManageAccount. To Set up a new company the user first enters the account number and clicks search. If the account number already exists the user can click on a button to go to the ManageAccount view. In the SetUpNewCompanyController I redirect using the RedirectToAction method. However, when the Index2 action in ManageAccount is executed the view is not displayed. If I type in the complete URL the view is displayed.

SetUpNewCompanyController.cs

[HttpPost]
 public RedirectToRouteResult RedirectToManageAccount(string accountNumber)
 {
        return RedirectToAction("Index2", new RouteValueDictionary(new {controller=
            "ManageAccount", companyId = "7e96b930-a786-44dd-8576-052ce608e38f" }));
 }

This above is called by the function below when a button is clicked

self.redirectToManageAccount = function () {
        var accountNumber = "7e96b930-a786-44dd-8576-052ce608e38f";
        $.ajax({
            type: "POST",
            url: "/SetUpNewCompany/RedirectToManageAccount",
            data: { accountNumber: accountNumber },
            success: function (data) {
            },
            error: function () {
            }
        });
 }

ManageAccountController.cs

public ActionResult Index2(String companyId)
    {
        var viewModel = new Models.Index();

        List<String> compList = new List<String>();
        compList.Add("MyCompany");

        List<String> usersList = new List<String>();
        usersList.Add("User1");

        viewModel.Users = usersList;
        viewModel.Companies = compList;
        viewModel.CompanyId = companyId;
        viewModel.Role = "Role1";

        return View("ManageAccount",viewModel);
    }

The URL that is generated is

http://localhost:53897/ManageAccount/Index2?companyId=7e96b930-a786-44dd-8576-
052ce608e38f

The console window in Firebug shows

GET http://localhost:53897/ManageAccount/Index2?companyId=7e96b930-a786-44dd-8576-
052ce608e38f 200 OK and the spinner keeps spinng

Also, how do I get the URL below instead of the one with querystring

http://localhost:53897/ManageAccount/Index2/7e96b930-a786-44dd-8576-052ce608e38f
  • 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-09T21:02:50+00:00Added an answer on June 9, 2026 at 9:02 pm

    Since you use AJAX to call the RedirectToManageAccount action method, you are responsible for handling its response yourself and as your success handler function is empty, you are effectively ignoring whatever arrives as a response.

    If you want to force a redirect from within the AJAX response handler, I suggest

    1. Modifying your action method as follows

      [HttpPost]
      public ActionResult RedirectToManageAccount(string accountNumber)
      {
          var redirectUrl = new UrlHelper(Request.RequestContext).Action("Index2", "ManageAccount", new { companyId = "7e96b930-a786-44dd-8576-052ce608e38f" });
          return Json(new { Url = redirectUrl });
      }
      
    2. Updating your AJAX call in this way

      self.redirectToManageAccount = function () {
        var accountNumber = "7e96b930-a786-44dd-8576-052ce608e38f";
        $.ajax({ type: "POST",
                 url: "/SetUpNewCompany/RedirectToManageAccount",
                 data: { accountNumber: accountNumber },
                 dataType: 'json',
                 success: function (response) {
                     window.location.href = response.Url;
                 },
                 error: function () {
                 }
        });
      }
      

    As for your second question:

    Also, how do I get the URL below instead of the one with querystring
    http://localhost:53897/ManageAccount/Index2/7e96b930-a786-44dd-8576-052ce608e38f

    You just have to define an appropriate route entry for this URL in your RegisterRoutes() function:

    routes.MapRoute(null,
                    "ManageAccount/Index2/{companyId}",
                    new { controller = "ManageAccount",
                          action = "Index2" }                            
    );
    

    EDIT: As your AJAX call only serves to call an action method which causes a redirect, you can simplify it in a following way, provided you in this point (on the client side) know the companyId already:

    self.redirectToManageAccount = function () {
        var companyId = "12345";
        window.location.href = '@(Html.ActionUri("Index2", "ManageAccount"))?companyId=' + companyId;
    }
    

    where I used this extension method

    public static string ActionUri(this HtmlHelper html, string action, string controller)
    {
        return new UrlHelper(html.ViewContext.RequestContext).Action(action, controller);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am building a new web site using asp.net mvc3 web application ,, and
I am building a new asp.net MVC3 web application for reporting and I want
I'm building a web application using MVC3 and I'm wondering what the etiquette is
I am building a Web application using MVC3 .NET The app should somehow keep
Here is my problem. I'm building a web application using MVC3 framework. My application
I currently building web management system using mvc3 In my application i have system
I'm a web developer new to using the MVC3 framework. We're building a site
I'm building a MVC3 application that needs to store secure user information such as
I am building a test application using MVC3, Razor, and Entity Framework 4.1 with
I am building a local intranet web application which uses the current user's AD

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.