I have this JS function:
<script type="text/javascript">
$(function ShowBMI() {
$.getJSON('/BMICalculations/ShowBMI', function (data) {
alert(data.CalculatedBMIResult);
});
});
And in my BMICalculations controller I have this method:
public JsonResult ShowBMI(){
BMICalculation BMI = new BMICalculation();
var data = Json(new
{
CalculatedBMIResult = 6
});
return Json(data, JsonRequestBehavior.AllowGet);
}
I call the JS function using the Onclick event of my submit button. The JS alert says 'undefined'. My Chrome console says that ShowBMI() is undefined but how could this be? Since its defined properly in my controller?