Mahesh Bodepudi

Mahesh Bodepudi

  • NA
  • 90
  • 56.6k

JavaScript runtime error: 'YearChange' is undefined

Nov 29 2016 6:39 AM
Hi,
I am working with MVC4
In this my controller code is like this
public JsonResult GetMonthByYear(int Year)
{
var lst = PODb.orders.Where(x => x.Year == Year).Distinct().ToList().FirstOrDefault();
long lnSupName = Convert.ToInt64(Year);
po po = PODb.poes.Where(x => x.ID == lnSupName).FirstOrDefault();
string strSupplierPhno = PODb.poes.Where(x => x.ID == po.ID).Select(c => c.OfficePhoneNo).FirstOrDefault();
string strContactPerson = PODb.poes.Where(x => x.ID == po.ID).Select(c => c.Contacts).FirstOrDefault();
return Json(new { suplierPhnNo = strSupplierPhno, contactName = strContactPerson });
}
 I have written the below code in my view
function YearChange() {
alert("strsupName");
var strsupName = $('#Year_ID').val();
if ((strsupName) != "")
{
alert(strsupName);
var options = {};
options.url = "/PO/GetMonthByYear";
options.type = "POST";
options.dataType = "json";
options.data = { Year: $("#Year_ID").val() };
options.success = function (result) {
var Text_PhnNumber = result.;
document.getElementById("txtSupplierPhnId").value = Text_PhnNumber;
var Text_ContactPerson = result.contactName;
document.getElementById("txtcontactId").value = Text_ContactPerson;
}
$.ajax(options);
}
}
 
@Html.DropDownListFor(x => x.Year,(IEnumerable<SelectListItem>)ViewData["Year"], "Year", new {Id = "Year_ID", @onchange = "return YearChange();" }) 
 with the above code I want to populate another Months dropdown when particular year is changed.
I am getting the below exception
 JavaScript runtime error: 'YearChange' is undefined
 Also i added the below references
<script src='http://code.jquery.com/jquery-latest.min.js' type='text/javascript'></script>
<script src="~/js/jquery.js"></script> 
<link href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.min.css" rel="stylesheet" type="text/css" />
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.min.js">
</script>
 
Please help on this 
 

Answers (2)