I have used this set up a number of times but can't see why it is not working here. Essentially the call to the controller seems to work, but returns an empty string, not the partial HTML.
I can render the partial like this so guess it is not the view itself:
@{
Html.RenderPartial("_MyPartial")
}
Here is the clean AJAX code, which is called from a parent razor view on document ready and calling the controller :
var container = $("#container");
var controllerUrl = "some/url";
var data = {};
$.ajax({
type: 'POST',
url: controllerUrl,
data: data,
dataType: 'html',
cache: false,
success: function(html) {
// Return HTML to page
// html is empty string at this point???
container.html(html);
},
error: function(jqXhr, textStatus, errorThrown) {
// Error occured so return message to page
container.html('<p>An error has occurred</p><p>' + jqXhr + '<p/><p>' + textStatus + '<p/><p>' + errorThrown + '<p/>');
}
});
And this is the controller:
[HttpPost]
public ActionResult ReportModels()
{
var viewModel = new ViewModel(); // props get set in original code
return PartialView("_MyPartial", viewModel);
}