Blabla Blabla - 1 year ago 64
Ajax Question

Pass c# list to the controller via JS

I do not have idea how to pass the full list by the Ajax. So i have c# list in the cshtml file and I want to pass it to the controller via Ajax. I know how to Pass simple variable, but don't know how to pass full list of objects. there is a simple js script:

$.get("/home/function?List=" + SthList, function (r) {

It should not work, because
isn't SJ object. But when I want to use razor it does not work anyway.

There is a controller

public ActionResult function(List<Object> List)
return PartialView(sth);

do you have any tips for me?

Answer Source

First, you need to transform your C# Array into a JsArray. To do that you need to mix razor and javascript.

There is a question for how to do that ( how to convert c# array into a js array?) Mix Razor and JavaScript

The other problem is passing array via ajax to the controller.

There is another question for that. Post array to mvc controller

So you can find your answer with this questions.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download