开发者

Ajax actionlink on page load

开发者 https://www.devze.com 2022-12-20 09:05 出处:网络
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 t

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?


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.


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消