Hi,
I had my view like,
Controller
@Html.DropDownList("CompanyID", null, "Select Company", new { onchange = "GetDiv()" })
@Html.DropDownList("WarehouseID",null, new { @class = "warehouse-select" })
on my CompanyID dropdown select I need my WarehouseID so,
I wrote the
javascript code like,
function GetDiv() {
debugger;
var warehouseno = $("#CompanyID").val();
$.ajax(
{
type: "POST",
url: "@Url.Action("GetWarehouseDropdown", "SearchJDE")",
dataType: 'json',
data: { id: warehouseno },
success: function (result) {
$("#WarehouseID").html("");
for (var i = 0; i < result.length; i++)
{
var item = result[i];$("#WarehouseID").append($("<option></option>").val(item.Value).html(item.Text));
}
},
error: function (req, status, error) {
}
});
}
my controller:
[HttpPost]
public JsonResult GetWarehouseDropdown(string id)
{
ViewBag.ModuleName = "OperManag";
if (Session["userName"] != null)
{
strUserName = Session["userName"].ToString();
}
IList<SelectListItem> objWarehouseMaster = (from s in db.WarehouseMasters
join u in db.UserPermissionMappings on new { s.CompanyID, s.IsDeleted } equals new { u.CompanyID, u.IsDeleted }
where u.UserID == strUserName && s.CompanyID == id && s.IsDeleted == false
select new SelectListItem() { Text = s.WarehouseID + "-" + s.WarehouseName, Value = s.WarehouseID }).ToList<SelectListItem>();
return Json(objWarehouseMaster, JsonRequestBehavior.DenyGet);
}
Here my controller can fetch the data but javascript function success is not working
Please help me