I try to render partial view and place between div elements. I read few articles e.g. Rendering a partial view with jquery but still doesn't work.
Where I made mistake?
A.) Place where I want to render my partial view:
<div id="target">
</div>
If I put between and @Html.Partial() I received error!
B.) How I call controler action:
$("#target").load('@Url.Action("GetMessageTypeView", "EmailMessages")');
I also tried with:
$.ajax({
url: '@Url.Action("GetMessageTypeView", "EmailMessages")',
type: "POST",
contentType: "application/json; charset=utf-8",
success: function (data) {
$('#target').html(data);
}
});
In both cases I called controller action, but no result.
C.) My controller action:
public ActionResult GetMessageTypeView()
{
return PartialView("Partials/MessageTypes");
}
Where I made mistake? Is it possible to render partial view and put somewhere in the page without call controler? Thanks
<div id='target'></div>.@Html.Partial()? (the action method does not seems to be modifying the partial view in any way)GetMessageTypeView()so the view you return will always be the same (herefore why not load it initially). However there appears nothing wrong with the.load()method (see Phaeze answer for issues with the.ajax()method. I suspect its the view or the name of the view. Put a breakpoint inGetMessageTypeView()and check that it gets hit. PS. to reply to a comment, precede with "@Stephen.."