views:

826

answers:

3

Is there a way to specify multiple update target ids with Ajax.ActionLink so that I can render a set of partial views on callback?

The problem that I'm seeing is that Ajax.ActionLink only provides one target id for me to update, but what I need is to update multiple regions of the page with different data after an ajax call.

Any help on this would be great! Thanks!

+1  A: 

No, there isn't. You could, however, write code which does this yourself. You would need to:

  1. Partition the returned HTML into different "areas" which you will apply to different parts of the page. You could do this on the controller (perhaps by rendering multiple actions and storing a list of the HTML fragments returned) or in JavaScript.
  2. Write JavaScript code to take the returned HTML, iterate the targets you'd like to update, and apply the appropriate HTML fragment to each. The code would look something like the code below.
  3. Don't use the Ajax form HTML helper. Instead, render a standard form and submit it via JavaScript.

Example:

$.ajax({
    type: "POST", 
    url: "/action/controller",
    success: function(data) {
        var key;
        for (key in data) {
            $("#" + key).html(data[key]);
        }
    }
 });

This presumes that the action you call will return an object where the property names are the IDs of the elements to update, and the property values are the HTML fragments as strings.

Craig Stuntz
+2  A: 

You can check this link: http://devlicio.us/blogs/sergio%5Fpereira/archive/2009/08/23/asp-net-mvc-with-jquery-superload.aspx

I had the same problem and it helps me to solve it

Gregoire
i used this, worked, with minor changes to get it to work in VB. still, it's a messy solution. The mvc team need to be smacked in the head for resorting us to this, why can't they just make a framework that WORKS and does common, basic every-day things as one would expect?
Erx_VB.NExT.Coder
A: 

i have this exact same problem and cannot solve it! looking for an elegant solution. i can't believe mvc can't handle this, i figured im just looking at it the wrong way, how else is this possible? anyone?

Erx_VB.NExT.Coder