0

I want to access the Array posted to the Controller's action in stringified format as,

for (var i = 0; i < passengers.length; i++) {
                var tmp = passengers[i].split(",");

                    datasource.insert({ PassengerID: 0, PassengerName: tmp[0], ID: tmp[1], Type: "Adult" });
                    models.push({ PassengerName: tmp[0], ID: tmp[1], PassengerType: "Adult" })
            }

            $.ajax({
                type: 'POST',
                url: '/Document/Passenger_Create',
                data: { models: JSON.stringify(models) },
                success: function (data) {

                    datasource.data
                }
            })

which is posted in Stringified format like,

models:[{"PassengerName":"test1","ID":" testing","PassengerType":" 123"},{"PassengerName":"test2","ID":" testing","PassengerType":" 123"},{"PassengerName":"test3","ID":" testing","PassengerType":" 123"},{"PassengerName":"test4","ID":" testing","PassengerType":" 123"},{"PassengerName":"test5","ID":" testing","PassengerType":" 123"}]

And inside of Controller I want to access those data Like ,

public ActionResult Passenger_Create([DataSourceRequest] DataSourceRequest request, IEnumerable<PassengerViewModel> models)

But it is not accessible. Please help me on this ASAP.

Rahul
  • 2,309
  • 6
  • 33
  • 60
  • So you saying that you have checked the "models" array at run time and it definitely looks exactly like what you posted above? <-- that's kind of important – user1567453 Nov 14 '13 at 03:26
  • The next thing would be to put a break point in your Passenger_Create(...) function to see what your variables look like so you can access them in the appropriate way...the information given for your asp page isn't quite enough and "not accessible" doesn't make much sense in the context for me. Could you make it more clear? – user1567453 Nov 14 '13 at 03:30
  • check this : http://stackoverflow.com/questions/1334479/json-decoding-in-c-sharp or this : http://stackoverflow.com/questions/2246694/how-to-convert-json-object-to-custom-c-sharp-object – andri Nov 14 '13 at 03:32
  • I have found the Answer, I have just Stringified the model and accesed it in Action as List – Rahul Nov 14 '13 at 07:25

0 Answers0