如何从级联下拉列表中获取stateId

时间:2017-12-01 14:15:55

标签: jquery asp.net-mvc

我在这里使用Mvc与JQUERY请帮助我如何从状态dropdownList获取State_Id

@using (Html.BeginForm("SaveEmployee", "Customer", FormMethod.Post, new { @class = "form-horizontal" }))
{ 
<b>Country</b>            
    @Html.DropDownListFor(cnt => cnt.SaveEmployee.Cnt_Id, new SelectList(Model.GetCountry, "Cnt_Id", "Cnt_Name"),"Select Country")
<b>State</b> <select id="DDlState" class="form-control"></select>

这里当我的国家Drp更改其获取状态值但是当我点击提交btn时我没有能够2绑定stateId

JqueryCode

var ddlStates = $('#DDlState');
ddlStates.append($('<option/>', { value: "-1", text: "Please Select State" }))
 $.ajax({
   url: 'http://localhost:47237/Customer/GetStateById/' + stsId,
   method: 'GET',
   dataType: 'Json',
   // data:stsId,
 }).success(function (data) {
   console.log(data);
   $.each(data,function (i,Items) {
     $(ddlStates).append($('<option/>', { value: Items.Sts_Id, text: Items.Sts_Name }))
     ddlStates.attr('disabled', false);
 })

1 个答案:

答案 0 :(得分:0)

请提供

<select id="DDlState" class="form-control" name="SaveEmployee.Sts_Id"></select>

我希望它会起作用