I found the solution. and it is working perfectly.
Here is that JQUERY code.
<script type="text/javascript">
$(document).ready(function () {
$("#ProductList").change(function () {
var selectedProductID = { productID: $("#ProductList").val() };
$.ajax({
url: '@Url.Action("GetProductData", "Home")',
type: 'Post',
contentType: 'application/json',
dataType: 'json',
data: JSON.stringify(selectedProductID),
success: function (data) {
if (data.success) {
document.getElementById("ProductName").value = data.productName;
}
else {
alert('invalid ID' + data.success);
}
}
});
});
});
</script>
CONTROLLER CODE
[HttpPost]
public JsonResult GetProductData(string productID)
{
Product product = Product.GetProduct(Convert.ToInt32(productID));
if (product != null)
{
return Json(new { success = true, productName = product.ProductName});
}
return Json(new { success = false });
}
I still do not know what is the difference but atleast it is working fine.