views:

72

answers:

2

Greetings, I have an asp.net mvc application. When button is clicked (submit button) i would like to results to be displayed inside some div. I know how to do it. I have some action where I return a partial view. But when button is submitted then I get some multiple objects from db and I would like to display them all in div. How can I achieve it?

A: 

Wrap all those objects in a wrapper object and pass that object to your partial view. Strongly type your partial view to the wrapper object and you are done!

Mahesh Velaga
A: 

Your action method could serialize and return them as a JSON encoded string:

public ActionResult Foo()
{
    SomeEntity[] entities = FetchEntities();
    // The JsonRequestBehavior is necessary only in ASP.NET MVC 2.0
    return Json(entities, JsonRequestBehavior.AllowGet);
}

which could be invoked like this:

$.getJSON('/home/foo', function(json) {
    $(json).each(function(index, value) {
        // SomeProperty is a property of your entity:
        $('body').append('<div>' + value.SomeProperty + '</div>');
    });
});
Darin Dimitrov