0

JS

var arrSpecialInstructions = [];
arrSpecialInstructions.push("sder");
arrSpecialInstructions.push("vfgtr");
$.ajax(
{
    url: "/PetBooking/CreditCardBookingProcess/",
    data:
    {
        'arrSpecialInstructions': JSON.stringify(arrSpecialInstructions)
    },
    type: 'POST',
    success: function (data, status, xhr) {},
    error: function (xhr, textStatus, errorThrown) {}
});

Action method

[HttpPost]
public ActionResult CreditCardBookingProcess(string arrSpecialInstructions)
{
    var specialInstructionsArray = arrSpecialInstructions.Split(',');
}

I just need to retrieve the comma separated string array.But it gives as below.How can I get just simple string array like this sder,vfgtr after splitting it.At this moment it's having lots of other characters.

enter image description here

1 Answer 1

1

No need to stringify just use join() :

data: { 'arrSpecialInstructions': arrSpecialInstructions.join() },
Sign up to request clarification or add additional context in comments.

4 Comments

It says : Uncaught TypeError: Object [object Array] has no method 'split'
oh pardon me i meant join not split :/
Yep.It's working.Thanks a lot.But one thing,Can you tell me why 'stringify' is not working here ?
Technically it's working but you would need to parse the json on the server side to obtain the array. This way you can just do split like you wanted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.