Click here to Skip to main content
15,744,010 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I tried with Dropdown change method .But its not getting.

By Ajax method i am calling one more method and its not hitting.

What I have tried:

In controlller::::


        public ActionResult DropDownBasic()
        {
            ViewBag.CountyList = new SelectList(az.GetCountryList(), "CountryId", "CountryName");
            ViewBag.Store = 1;
            ViewBag.StateList = new SelectList(az.GetStateList(), "StateId", "StateName");
           return View();
        }


 public ActionResult DropDownBasic1(int CustomerId)
        {
            ViewBag.CountyList = new SelectList(az.GetCountryList(), "CountryId", "CountryName");
            ViewBag.StateListById = new SelectList(az.GetStateList(CustomerId), "StateId", "StateName");

            return View();
        }



view:::


@{
    ViewBag.Title = "DropDownBasic";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>DropDownBasic</h2>


@model  AZ.WebUI.Models.Input

<div>
    @Html.DropDownList("Moving", new SelectList(ViewBag.CountyList as SelectList,"Value","Text"),"Select City",new { Id = "Co", onchange =@"Fill();" })

    @Html.DropDownList("States", new SelectList(ViewBag.StateList as SelectList, "Value", "Text"),"Select state")
  
</div>

<script>


    function Fill() {
        var value = $("#Moving").val();
        if (value) {
            $.ajax({
                url: '@Url.Action("DropDownBasic1", "Customer")/' + value,
                type: 'GET',
                dataType: 'json',
                success: function (data) {
                  
                }
            });
        }

 }

</script>
Posted
Updated 28-Feb-17 19:34pm

1 solution

change this
var value = $("#Moving").val();
to
var value = $("#Co").val(); // you have declared  Co as id


change it to
new { Id = "Co", onchange="Fill(this);" })

function Fill(obj) {
       var value = obj.value;
       alert(value);
   }
 
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