aditya immadi

aditya immadi

  • NA
  • 215
  • 22k

AJax calls not working in mvc

May 30 2016 2:51 AM
hai all,while i m calling ajax calls i not able to call methos in my controller here is my code
 
 
<title>ViewCompanyProfile</title>
@{
UsersDAL obj = new UsersDAL();
List<SelectListItem> CompanyName = new List<SelectListItem>();
DataTable dtCompanyDetails = obj.ShowCompany();
foreach (DataRow row in dtCompanyDetails.Rows)
{
CompanyName.Add(new SelectListItem { Value = row["CompanyId"].ToString(), Text = row["CompanyName"].ToString() });
}
}
<script src="~/Scripts/jquery-1.7.1.min.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
<script>
function ShowCompany($this)
{
var CompanyName = $("#Company_Name").val();
alert("hello");
$.ajax({
URL: '/Admin/ShowCompany',
type:"GET",
datatype:"JSON",
data: { CompanyId: CompanyName },
success:function(s){
document.getElementById("table").innerHTML='<div style="margin-top:2%"><h2> '+s[0]+'</h2><hr><p>'+s[1]+'</p><p>'+s[2]+'</p><p>'+s[3]+'</p></div>';
alert("hello");
}
});
alert("Welcome");
}
</script>
</head>
<body>
<div>
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
<h1>Select Company</h1>
@Html.DropDownListFor(Model => Model.CompanyName,CompanyName ,"Select", new {@id="Company_Name",@onchange="ShowCompany(this)" })
}
</div>
</body>
 
 
and  in my controller
 
public ActionResult ViewCompanyProfile()
{
return View();
}
[HttpPost]
public ActionResult ShowCompany(int CompanyId)---------This one is not calling
{
DataTable dt = _objDAL.GetShowCompany(CompanyId);
int rowcount = dt.Columns.Count;
string[] strarray=new string[rowcount];
for (int i = 0; i < rowcount; i++)
{
strarray[i] = dt.Rows[0][i].ToString();
}
return Json(strarray,JsonRequestBehavior.AllowGet);
}
}
 
any suggestions are highly appreaciated
 
TIA 
 

Answers (4)