ASP.NET MVC submitting json array to controller as regular post request (nonajax)

Posted by j3ko on Stack Overflow See other posts from Stack Overflow or by j3ko
Published on 2010-04-24T03:21:13Z Indexed on 2010/04/24 3:23 UTC
Read the original article Hit count: 254

Filed under:
|
|
|

All the examples of json I can find online only show how to submit json arrays w/ the jquery command $.ajax(). I'm submitting some data from a custom user control as a json array. I was wondering if it's possible to submit a json array as a regular post request to the server (like a normal form) so the browser renders the page returned.

Controller:

[JsonFilter(Param = "record", JsonDataType = typeof(TitleViewModel))]
public ActionResult SaveTitle(TitleViewModel record)
{
    // save the title.
    return RedirectToAction("Index", new { titleId = tid });
}

Javascript:

function SaveTitle() {
    var titledata = GetData();

    $.ajax({
        url: "/Listing/SaveTitle",
        type: "POST",
        data: titledata,
        contentType: "application/json; charset=utf-8",
     });

}

Which is called from a save button. Everything works fine but the browser stays on the page after submitting. I was thinking of returning some kind of custom xml from the server and do javascript redirect but it seems like a very hacky way of doing things. Any help would be greatly appreciated.

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about JSON