I have some code that doesn't seem to be working correctly. I'm sure that there is just something I'm missing, but I've beaten my head against it too long already and am getting nowhere.
Here is the AJAX call:
$.ajax({
type: 'POST',
url: '@Url.Action("GetPartial", "MyPage")',
async: true,
data: {
MyID: 'ABC123'
},
error: function (jqXHR, textStatus, errorThrown) {
alert('Error loading partial for ' + MyId + '\n\n' + jqXHR + '-' + textStatus + '-' + errorThrown);
}
}).done(function (result) {
$(data).html(result);
});
Here is the action in MyPageController.cs:
[HttpPost]
public PartialViewResult GetPartial(string MyID)
{
return PartialView("ThePartial");
}
In my Views diretory I have a MyPage subdirectory, which contains ThePartial.cshtml.
I have put breakpoints in that cshtml and it doesn't appear to ever be called.
In addition, I have verified that the PartialView is empty by changing my action code slightly to:
[HttpPost]
public PartialViewResult GetPartial(string MyID)
{
PartialViewResult pView = PartialView("ThePartial");
return pView;
}
and then putting a breakpoint on the "return" line and looking at the contents of pView.
Following is an abbreviated version of the partial view.
@model MyProject.Models.MyModel // There is a breakpoint here
@{
var x = "testing"; // There is a breakpoint here
x += " 123"; // There is a breakpoint here
}
<div>@x</div>
I actually have breakpoints set on the first, third, and fourth lines that have never been hit.
I realize that the partial refers to a data model that is not included in the action, but in the actual version the model IS used. I removed it from this post to keep it short, thinking that the model wasn't where the issue was. Here is the actual PartialView call:
MyData myData = MyModel.GetData(MyID);
PartialViewResult pView = PartialView("ThePartial", myData);
I'm completely lost on this and would appreciate any assistance at all.