0
A
답변
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>
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
안녕하세요 - 시도해보십시오. –
관련 문제
- 1. DropDownList로
- 2. 바인딩 DropDownList로
- 3. RowDataBound DropDownList로
- 4. DropDownList로 동적은
- 5. DropDownList로 화재를 두 번
- 6. 양식로드 콤보 상자 DropDownList로
- 7. MVC3 DropDownList로 코드 먼저
- 8. YII DropDownList로 기본값
- 9. DropDownList로 오류가 ASP.NET
- 10. DropDownList로 다시 게시
- 11. TextBox에서 DropDownList로 변경
- 12. <S : DropDownList로 selectedItem가
- 13. YII : 관계와 DropDownList로
- 14. DropDownList로 액세스 할 수
- 15. 종속 종속 버전?
- 16. 레일 종속 종속 파괴
- 17. 다른 종속 종속 속성
- 18. 데이터 소스를 dropdownlist로 설정하는 방법
- 19. DropDownList로, 많은 ListItems 및 selectedItem가
- 20. mvc3 DropDownList로 검증 모델에 optionLabel
- 21. 또 다른 viewstate가 DropDownList로 문제
- 22. 변경 이미지 소스 : DropDownList로 선택
- 23. DropDownList로 ASPX EventValidation 오류가 발생했습니다.
- 24. DropDownList로 첫 번째 값 표시
- 25. ASP.NET MVC DropDownList로 유효성 검사
- 26. ASP.NET ListBox 컨트롤을 DropDownList로 변환
- 27. 철근 종속
- 28. 종속 속성
- 29. 플레이는 종속
- 30. 종속 콤보?
은 면도기보기 –
를 영문으로 변경 - 스리 나스 - 당신은 나에게 완전한 작업 샘플을 보낼 수 있습니까? rick.anderson [at] Microsoft.com – RickAndMSFT
잘 작동합니다. 릭 –