AspnetMvc 리셋 없음

3317 단어 asp
1. Control 레이어
/// <summary> /// action          json        /// </summary> /// <param name="p">    </param> /// <returns></returns> public ActionResult GetCityList(string p) { ; IList<City> cityModelList =//             var pList = new SelectList(cityModelList, "CityId", "CityName"); return Json(pList, JsonRequestBehavior.AllowGet); } //       public void BindProvince(string defaultText = "   ", string defaultValue = "") { var dt =//      IList<SelectListItem> items = new List<SelectListItem>(); items.Add(new SelectListItem { Text = defaultText, Value = "", Selected = true }); foreach (var dr in dt) { items.Add(new SelectListItem { Text = dr.ProvinceName, Value = dr.ProvinceCode }); } this.controller.ViewData["Province"] = items; this.controller.ViewData["ddlProvince"] = defaultValue ?? string.Empty; } //       public void BindCity(string provinceId, string defaultText = "   ", string defaultValue = "") { IList<SelectListItem> items = new List<SelectListItem>(); if (provinceId == string.Empty) { items.Add(new SelectListItem { Text = defaultText, Value = defaultValue }); } else { var dt = //             foreach (var dr in dt) { items.Add(new SelectListItem { Text = dr.CityName, Value = dr.CityId }); } } this.controller.ViewData["City"] = items; this.controller.ViewData["ddlCity"] = defaultValue ?? string.Empty; }
2、View 
<script src="@Url.Content("~/Scripts/provinceCity.js")" type="text/javascript"></script>

<div class="editor-label">
                
        </div>
        <div>
            @Html.DropDownList("ddlProvince", ViewData["Province"] as IEnumerable<SelectListItem>)
            @Html.DropDownList("ddlCity", ViewData["City"] as IEnumerable<SelectListItem>)
            @Html.ValidationMessageFor(model => model.CityId)
        </div>


    //       js  ,  url   
    @Html.Hidden("GetCityList", Url.Action("GetCityList", "Enterprise")) 
3、Js  
     $(document).ready(function () {     $("#ddlProvince").change(function () { getCity($(this).val()); });function getcity(provinveCode) {$("#ddlCity").html(");//$.ajax({type:"GET",url: $("#GetCityList").val(),data:"p="+ provinveCode +"&date="+ new Date(),dataType:"json",            success: function (json) {                if (json.length > 0) {                    for (var i = 0; i < json.length; i++) {                        $("#ddlCity").append("");} else {$("#ddlCity"). append(""을 선택하십시오).                }            },            error: function (data) {                alert(data);            }         });    }});

좋은 웹페이지 즐겨찾기