user1069516
user1069516

Reputation: 463

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

Upvotes: 0

Views: 765

Answers (1)

user1069516
user1069516

Reputation: 463

In fact I found the solution by adding only string parameter in url :

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

Upvotes: 1

Related Questions