I'm trying to get a json serialized object from within an MVC user control using jQuery. The problem is the result coming back is the full HTML for the page that contains my control. The page and the control use the same controller. I've tried breaking on the method I'm calling in the controller and it never gets hit. I've tried various incarnations of the jQuery Ajax calls, and get the same result.
jQuery code:
<script type="text/javascript">
$('#Project_GeneralContractor_Id').change(function() {
//alert('<%= Url.Action("GetGeneralContractor", "Projects") %>/1');
$.get('<%= Url.Action("GetGeneralContractor", "Projects") %>', { id: $('#Project_GeneralContractor_Id').val() }, function(data) {
alert(data);
});
});
</script>
Controller code:
public JsonResult GetGeneralContractor(int id)
{
return Json(_GeneralContractorRepository.Get(id));
}
Where $('#Project_GeneralContractor_Id') is a drop down list and _GeneralContractorRepository.Get(id) returns an individual GeneralContractor object.
Not sure what I have going on, but I suspect the jQuery side since I can't seem to get a break in the controller.