mardi 1 décembre 2015

Send JSON object and string parameters simultaneously

Is it possible to post with jquery JSON object and a string parameter to MVC3 controller method ?

This is my function in the controller :

public void myFunction(List<myObject> obj, string myStringparameter)

And my javascript function (without string parameter) :

$.ajax({
    url: "../MyController/myFunction,
    type: "POST",
    processData: false,
    contentType: "application/json; charset=utf-8",
    data: JSON.stringify({ obj: tabJsonObject})
}).success(function (data) {

    //TODO

})
.error(function (response, status, xhr) {
    //TODO
});

Without string parameter, it works correctly but I don't know how add this string parameter.

I can't add directly in the url because the URL is too long and I think that add this string in JSON array is bad.

Thanks for your help

Aucun commentaire:

Enregistrer un commentaire