I'm trying my hand at Json for the first time and I'm not sure what I'm doing wrong here, but my success callback to ever get called. I've got a dropdown called RIPreset, and it calls the below code on change. I know the on change part is working properly. In the code below my alert("popup1") code gets run, I also have a break point in my code behind and can see that the getPreset method is getting called and passing strings to the result, but nothing inside the function inside my .getJSON call. Ie, alert("popup2") never gets called. I take that to mean that I'm not passing valid data from my JsonResult, but I'm not sure what I'm doing wrong. Any help would be appreciated.
Code Behind
public JsonResult getPreset(int id)
{
RIPreset ripreset = db.RIPresets.Find(id);
return Json(new { Description = ripreset.Description, LaborHours = ripreset.LaborHours, HourlyRate = ripreset.HourlyRate, Amount = ripreset.Amount });
}
JQuery/Json
<script type="text/javascript">
$(document).ready(function () {
$("#RIPreset").change(function () {
var selection = $("#RIPreset").val();
alert("popup1");
$.getJSON('@Url.Action("getPreset")', { id: selection }, function (ripreset) {
alert("popup2");
$("#txtDescription").val(ripreset.Description);
$("#txtHourlyRate").val(ripreset.HourlyRate);
$("#txtLaborHours").val(ripreset.LaborHours);
$("#txtAmount").val(ripreset.Amount);
});
});
});
</script>