hai all,while i m calling ajax calls i not able to call methos in my controller here is my code
TIA
What I have tried:
<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='
'+s[0]+'
'+s[1]+'
'+s[2]+'
'+s[3]+'
';
alert("hello");
}
});
alert("Welcome");
}
</script>
</head>
<body>
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
Select Company
@Html.DropDownListFor(Model => Model.CompanyName,CompanyName ,"Select", new {@id="Company_Name",@onchange="ShowCompany(this)" })
}
</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);
}
}