Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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)); //$("#WarehouseID").trigger("liszt:updated");
                }
            },
            error: function (req, status, error) {
            }
        });
    }


my controller:
XML
[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
Posted
Updated 28-Apr-14 2:48am
v2

1 solution

You url (in $.ajax) is seems to be wrong. It should be along the line 'Controller/Action'...
Please read this: JQuery AJAX with ASP.NET MVC[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900