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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:43:53+00:00 2026-05-25T00:43:53+00:00

I was using some old example for MVC2, that used a [fromJson] attribute when

  • 0

I was using some old example for MVC2, that used a [fromJson] attribute when posting json to a controller action, it worked fine except that it did not catch model errors, so ModelState.IsValid is always true. Then I saw that posting JSON was build into MVC3 so I have upgraded my code. But now I have another issue 🙂 using:

ko.utils.postJson(location.href, json); 

The binding is not working, and my model is empty.

But if I use JQuery:

$.ajax({
                            url: '@Url.Action("Create")',
                            contentType: 'application/json; charset=utf-8',
                            type: "POST",
                            data: json,
                            dataType: 'json',
                            success: function(result) {
                                alert("yay");
                            },
                            error: function(xhr, ajaxOptions, thrownError) {
                                alert(xhr.statusText + " " + xhr.responseText);
                            }
                        });

So I think i will move my ko.utils.postJson to JQuery $.ajax but how do I just post so I can do a RedirectToAction afterwards?

So to clarify! the controller action looks like this:

public ActionResult Create(QuestionViewModel questionViewModel){

    if (ModelState.IsValid)
    {
        questionViewModel.Save();

        TempData.Add(Config.MODEL, questionViewModel);
        return RedirectToAction("Edit");
    }

    PopulateViewBag();

    return View(questionViewModel);
}

I have found this http://groups.google.com/group/knockoutjs/browse_thread/thread/e631a544de2ad51e in the Knockout forum so ko.utils.postJson is a “normal” form submit. which is what I want to do, so the flow of the application is kept unchanged.

  • 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-25T00:43:53+00:00Added an answer on May 25, 2026 at 12:43 am

    Since $.ajax() does not create a <form> tag and submit it, you cannot do things like RedirectToAction, during ajax posts. ko.utils.postJson allowed you to do all that because it internally created a quick form tag in the dom and submitted it via script.

    What you can do is :

    $.ajax({
      statusCode: {
        302: function() {
          window.location.replace("http://Domain.com/Controller/Edit")
        }
      }
    });
    

    This question helped me find the way to redirect browser via script. This page tells you how to handle different status codes returned by the server. ASP.NET MVC3 returns 302 status code when you use RedirectToAction() in the Controller. And this can be handled, by adding the approperiate handler as shown above.

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

Sidebar

Related Questions

I have some old code written in C for 16-bit using Borland C++ that
We have some really old code that calls WebServices using behaviours (webservice.htc), and we
I am using some custom controls one of which is a tooltip controller that
I reused some old code and come saw that I had been using this
I'm using Microsoft.XMLHTTP to get some information from another server from an old ASP/VBScript
I'm looking to parse some old html that has plenty of extraneous tags that
I'm using C# and .NET 3.5, trying to import some data from old dbf
I'm reading through some MSDN example code on Composite controls and finding that there
I am trying to render some old level data using the glDrawRangeElements() command. My
While delving into some old code I've stumbled upon a function which is used

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.