-3

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) {
    $("#Table").html(r);
});

It should not work, because SthList 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?

6
  • u can use json.net library. Commented Jul 25, 2016 at 12:35
  • What is the model and its properties. And what is SthList Commented Jul 25, 2016 at 12:35
  • SthList is a c# List<object>, it isn't really important what is the model. This questuion does not depend on this. Commented Jul 25, 2016 at 12:58
  • Of course it does! Commented Jul 25, 2016 at 13:12
  • It would make more sense to put a list in a form and POST it. Commented Jul 25, 2016 at 13:16

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

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.