I was returning JSON data of a Product from a controller JsonDetailsProduct. This is in turn called using the Jquery.
However, the success function of the Jquery call doesn't seems to be receiving any data. I guess Something is wrong within my controller.
MVC Controller:
public ActionResult JsonDetailsProduct(int id)
{
Product pdt = NWDC.GetProduct(id);
if (pdt == null)
{
// i'm throwing a custom exception here
throw new RecordNotFoundException();
}
else
{
return Json(new {
ProductId = prod.ProductID,
ProductName = prod.ProductName,
UnitPrice = prod.UnitPrice,
UnitsInStock = prod.UnitsInStock,
Discontinued = prod.Discontinued
}, JsonRequestBehavior.AllowGet);
}
}
the JQuery call:
<script type="text/javascript">
$(document).ready(
function(){
alert("About to make the call"); // just added it for my debugging purpose
$.getJSON( "/SlimProductServices/JsonDetailsProduct",
data:{id:$('#txtProductID').val()},
function(productData)
{
alert(productData);
}
);
}
);
Any thoughts where things are setup wrongly and whether any issue in Jquery Call also present ??
EDIT
Also, I corrected the data parameter of my Jquery call, but the first Alert box shows up after that blank pop ups.
[object Object].)data:id:$(...is invalid, you can't have two colons like that without curly brackets. Perhaps it should be{data : { id : $(...) } }or just{ id : $(...) }.