views:

246

answers:

2

Basically Im building an ASP.NET MVC Application. I have a search page. Its searches for results from a number of different sources. To aid in the speed of page load I decided to load the results from one source first then to dynamically load more results as it finishes searching other sources.

So far I have the first set of results returned and an Ajax.ActionLink working which renders a partial view in a div which shows results from a second source. However obviously I have to click on the actionLink to get the it to work.

What Im wondering is how to a use the actionlink to fire on page load so the further results arrive automatically? can i rewrite the actionlink in javascript/jquery and fire it on page load or what is the best practice for this kind of thing?

A: 

I really don't get the point in your question, you want to update the results pane as soon as results are ready? I think your approach is not the correct one, how are you going to retrieve the results of a search you started in a previous request?. I would suggest either to fire different async requests from the client-side (each of them for querying each of the different sources) or to use something like push-ajax (never tried that).

uvita
I want to add further results to the results already there. Its doing this for me at the minute with the ActionLink but instead of having to click the action link I want the results from the second source to appear on there own from the ajax request sent on page load.
Boob
Then, on every subsequent request you're going to be querying a different source? Why don't you specify a handler for the OnSuccess event where you specify a timeout after which you fire another search request? You can specify the handler by setting the name of the javascript method to call on the OnSuccess property of the AjaxOptions.
uvita
That idea I like! When I start adding more source systems I'll use the OnSuccess property as you described. However due to my poor grasp of jquery at the moment I'm still struggling to get an ajax get which replicates what my actionLink was doing for me. This is where my problem lies at the moment.
Boob
+1  A: 

Hey,

I've used JQuery to load the UI dynamically:

$.get("/controller/action", function(html) {
   //insert Html into page
   $("#rootelement").html(html);
});

You can have your action return a partial view to inject:

public ActionResult Act()
{
    return PartialView("SomeView");
}

Also, you may want to look at things in the MVC futures like the AsyncController or the RenderAtion helper method (though RenderAction isn't dynamic). Maybe some of those items may work too. Not used them personally.

HTH.

Brian
Thats exactly whats I was after! :) Thank you very much!
Boob