Ever wanted to re-use or re-load part of your page via AJAX with MVC 2/3. There is a really simple way to achieve this with PartialViews and jQuery’s .load() function.
1. Create a PartialView

2. Add some jQuery - AJAX .load():
[sourcecode language="javascript"]
$("#divForPartialView").load("/HelloWorld/GetAwesomePartialView",
{ param1: "hello", param2: 22}, function () {
//do other cool client side stuff
});
[/sourcecode]
3. Add your MVC Controller ActionResult that returns your PartialView:
[sourcecode language="csharp"]
public ActionResult GetAwesomePartialView(string param1, int param2)
{
//do some database magic
CustomDTO dto = DAL.GetData(param1, param2);
return PartialView("AwesomePartialView",dto);
}
[/sourcecode]
4. Add some client side code to make it happen
Hi, great tip here, helped me alot. Previously I have only loaded partial views using the html.actionlink. I noticed one must use the exact same key names in the jquery as the names of the method parameters in the controller action.
Just what i’ve been looking for!!
It’s really good article.
Keep it up your good work.