1
           $.ajax({
                url: '/Project/GetItemsBySearchKey',
                type: 'POST',
                dataType: "json",
                data: {
                    searchKey: "text",
                    exclussionList: [10,11]
                },
                success: function (data) {
                   alert(data);
                }
            });

I have this is javascript and below function in c# MVC controller

public ActionResult GetItemsBySearchKey(string searchKey, List<long> exclussionList)

The value in the searchKey get in controller buT the exclussionList become null always What is the error in my codes

2 Answers 2

1

Set .ajax "traditional" property to true for shallow array serialization and default model binder for the mvc will do the rest.

$.ajax({
                url: '/Project/GetItemsBySearchKey',
                type: 'POST',
                dataType: "json",
                traditional: true,
                data: {
                    searchKey: "text",
                    exclussionList: [10,11]
                },
                success: function (data) {
                   alert(data);
                }
            });

And aciton will be:

public ActionResult GetItemsBySearchKey(string searchKey, List<int> exclussionList)
Sign up to request clarification or add additional context in comments.

Comments

1

Try to pass it as string instead of array and split it at controller

exclussionList: [10,11].join("-")

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.