Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

Passing dropdown selected value to controller using ajax call

$
0
0

Hi devs, i am working with mvc 4 dropdown list, i want to pass the dropdown selected value to my controller on change event, which is not working. kindly do help me to resolve the same, for ur reference i have attached my code here following.

<script type="text/javascript">$(document).ready(function () {$("#productitem").change(function () {
            debugger;
            event.preventDefault();

            var $url = '/Home/getManufacturer';$.ajax({
                url: $url,
                type: 'POST',
                datatype: "json",
                data: "Item=" + $("#
productitem
").val(), data: { item: selectedValue }, success: function (response) { }, error: function (xhr, status, error) { // alert(error); } }); }); }); </script> <td> @Html.DropDownList("Items", null, new { @id = "productitem" }) </td>


 [HttpPost]
        public JsonResult getManufacturer(string item)
        {

            ItemStock obj = new ItemStock();
            Processor biz = new Processor();
            List<SelectListItem> itemManufacturer = new List<SelectListItem>();
            DataSet ds = new DataSet();
            ds = biz.getManufacturer();
            int row = ds.Tables[0].Rows.Count;
            itemManufacturer.Add(new SelectListItem { Text = "--Select Manufacturer--", Value = "0" });
            for (int i = 0; i < row; i++)
            {
                itemManufacturer.Add(new SelectListItem { Text = ds.Tables[0].Rows[i].Field<string>("manufacturer"), Value = Convert.ToString(i + 1) });
            }

            return Json(itemManufacturer, JsonRequestBehavior.AllowGet);
        }


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>