I have a jQuery function that on the click of a div element, gets that elements predefined ID value. What I want to do is load that parent elements children, so I'm planning to dynamically build some html using jQuery. What I don't know how to do, is make a call to a controller (ASP.NET MVC 3) and have the controller return a collection to the client.
I know how to send a JSON object from jQuery to a controller, but not the other way around.
Thanks in advance!
Sample:
Javascript:
Controller:
Here is the code for how you send data from Controller to json:
Consider a class like the one below....
your action should look like this.
Further Reading
You can make use of the jquery
ajax
function and the MVC RazorUrl
property:The value of the success property is a function with one argument: data. This is the result of what is returned from your controller.