I'm trying to populate a div with a partial view in MVC 3. My controller looks like this:
[HttpPost]
public ActionResult GetCustomerList(string searchString)
{
var custService = new CustomerViewModels();
var custListVM = custService.GetSearchList(searchString);
return PartialView("GetCustomersList", custListVM);
}
and my jQuery call looks like this:
function getCustomerList(searchCriteria) {
$.ajax({
url: 'Home/GetCustomerList',
type: 'POST',
async: false,
data: { searchString: searchCriteria },
success: function (result) {
$("#customerTabBody").html(result);
}
});
};
It works fine. I began to wonder if I could use the jQuery load method to do the same thing with a lot less code and wrote this:
function getCustomerList(searchCriteria) {
$("#customerTabBody").load('Home/GetCustomerList', { searchString: searchCriteria });
};
It returns an error saying the resource can't be found. I've tried using @Url.Action but it encodes the same controller path I have hard coded. In Firebug I can see that the URL that is being posted to is the same and the searchString parameter is identically formatted in both instances.
What's the difference - why does load not work?
Thanks