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 3314658
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:15:31+00:00 2026-05-17T22:15:31+00:00

I have an ASP.NET MVC Form, but the data from it needs to be

  • 0

I have an ASP.NET MVC Form, but the data from it needs to be posted via jQuery (not ajax). It cannot be submitted using the normal model, because the Controller Action requires a JSON string, and the only way to get that string is to use jQuery’s $.post method to turn the data into JSON, and then post it to the Controller.

This works fine. However the end result is that after posting, the form is supposed to Redirect to a different page (Like a Success Page). This does not occur, it just stays on the same page.

If I use return false; in my jQuery code, it will stop the form from trying to post again, but this doesn’t solve my problem. I really don’t want to set the URL manually, either, since I want to keep as much out of javascript as humanly possible.

Controller

    [HttpPost]
    public ActionResult Receive([FromJson] jsonObject item)
    {
        if (ModelState.IsValid)
        {
                       // logic
        }
        return RedirectToAction( ... );
    }

JavaScript

            $('.submit').click(function(e) {
                    var json = JSON.stringify(data);
                    $.post( location.href, { item: data});
            });

This submits the code right. and the return statement even gets hit if I step through it in the debugger, but it never does the redirect. What can I do?

  • 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-05-17T22:15:32+00:00Added an answer on May 17, 2026 at 10:15 pm

    How about returning a string from your action that is the location you want to redirect to.

    Then in your success callback, use the javascript redirect method by setting window.location.

    E.g. NOTE: this is untested and probably doesn’t work exactly like this, but you get the jist.

    Controller

    [HttpPost]
    public ActionResult Receive([FromJson] jsonObject item)
    {
        if (ModelState.IsValid)
        {
                       // logic
        }
        return Json("urltoredirectto");
    }
    

    JavaScript

    $('.submit').click(function(e) {
        var json = JSON.stringify(data);
        $.post(location.href, { item: data },
            function (data) {
                window.location = data;
            });
    });
    

    HTHs,
    Charles

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have ASP.NET MVC application with action which should process posted XML data. At
I have an ASP.NET MVC project with a form. In the Action method that
I have an ASP.Net MVC Ajax.BeginForm that submits and updates my page properly when
I have an ASP.NET MVC 2 project in which I've created a data transfer
I have an ASP.NET MVC-application which I want deployable on both IIS6 and IIS7
I have an asp.net mvc application with a route similar to: routes.MapRoute(Blog, {controller}/{action}/{year}/{month}/{day}/{friendlyName}, new
I have an ASP.NET MVC (Beta 1) website that I'm using themes with. When
I have an ASP.NET MVC application, when a user clicks on the submit button
I have an asp.net mvc app running on a local iis website that is
I have an ASP.NET MVC view which contains checkboxes for user-defined categories. <td><% foreach

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.