2011-12-13 4 views
0

사이 나는 ASCX 파일이 선택 필드가 있습니다.
어떻게하면됩니까?
감사합니다.종속 DropDownList로

추신. ViewEngine은 WepPages입니다.

답변

1
cascading Country and state DDL 
    @Html.DropDownListFor(model => model.CountryId, Model.CountryList, "--Select Country--", new { @class = "CountryList", style = "width:150px" }) 

    @Html.DropDownListFor(model => model.StateId, Model.StateList, "--Select State--", new { @class = "StateList", style = "width:150px" }) 

    <script type="text/javascript"> 
     $(document).ready(function() { 
      $.post("/Client/GetModels", { id: $(".CountryList").val() }, function (data) { 
       populateDropdown($(".StateList"), data); 
      }); 
      $(".CountryList").change(function() { 
       $.post("/Client/GetModels", { id: $(this).val() }, function (data) { 
        populateDropdown($(".StateList"), data); 
       }); 
      }); 
     }); 

     function populateDropdown(select, data) { 
      $(".StateList").empty(); 
      $.each(data, function (id, option) { 
       $(".StateList").append("<option value='" + option.StateId + "'>" + option.State + "</option>"); 
      }); 
     } 
    </script> 
+0

은 면도기보기 –

+0

를 영문으로 변경 - 스리 나스 - 당신은 나에게 완전한 작업 샘플을 보낼 수 있습니까? rick.anderson [at] Microsoft.com – RickAndMSFT

+0

잘 작동합니다. 릭 –

1
 Try this 
     In view 
      <div class="popup_textbox_div" style="padding: 0pt;"> 
      <%=Html.DropDownList("CityId", new SelectList(Model.Cities, "Code", "Name", 0), "---Select City---", new { @class = "popup_textbox popup_dropdown valid" })%> 
      </div> 

       <div class="popup_textbox_div" style="padding: 0pt;"> 
       <select class="popup_textbox popup_dropdown valid" id="OID" name="Name"> 
       <option>---All Establishment---</option> 
      </select> 
      </div> 
    Add the script 

    <script type="text/javascript"> 
    $(function() { 
     $("#CityId").change(function() { 
      var cityId = $("#CityId").val(); 

      if (!isNaN(cityId) && (cityId > 0) && (cityId != null)) { 

       GetEstablishmentsByAjax(cityId); 
      } 
      else { 
       $("#OID").html("<option value=''>---All Establishment---</option>"); 

      } 
     }); 
    }); 

    GetEstablishmentsByAjax(cid) { 

     $.ajax({ 
      type: "GET", 
      contentType: "application/json; charset=utf-8", 
      url: "/trail/selectestablishment/" + cid.toString(), 
      data: "", 
      dataType: "json", 
      success: function (data) { 

       if (data.length > 0) { 

        var options = "<option value=''> --All Establishment---</option>"; 
        for (s in data) { 
         var type = data[s]; 
         options += "<option value='" + type.Value + "'>" + type.Text + "</option>"; 
        } 
        $("#OID").html(options); 

       } 

      } 
     }); 
    } 
    </script> 

In TrailController 

public ActionResult selectestablishment(int? id) 
     { 
       SelectList establishments = null; 
       var estb = //put ur code and get list of establishments under selected city 
       establishments = new SelectList(estb, "OID", "Name"); 
       return Json(establishments, JsonRequestBehavior.AllowGet); 

     } 
+0

안녕하세요 - 시도해보십시오. –