开发者

load a usercontrol using jquery

开发者 https://www.devze.com 2022-12-09 05:29 出处:网络
How to load/render a usercontrol using jquery? I have some menus on header of the page and the usercontrols for each menu. On click of the menus i need to re-load the content with the corresponding u

How to load/render a usercontrol using jquery?

I have some menus on header of the page and the usercontrols for each menu. On click of the menus i need to re-load the content with the corresponding usercontrol.

How can i achieve it using jquery which avoids开发者_如何学Python page refresh?


In JavaScript:

$("#someContainerForTheUserControl").load("/Controller/PartialAction");

In your controller:

public ActionResult PartialAction()
{
    return PartialView("SomeUserControl");
}


You want to use the jQuery AJAX functions (either post or get) to make a request to your server.

You will have a method in your code behind which returns the HTML of the usercontrol. When the page recieves the HTML you can just update a div with the returned markup.

There is a tutorial here which should talk you through the steps in detail:

http://www.aspcode.net/ASPNET-and-JQuery-updating-templated-controls-with-AJAH.aspx

Good luck

0

精彩评论

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