2013-01-15 3 views
0

여러 저장된 프로 시저를 사용하여 드롭 다운 목록을 채우는 페이지를 만듭니다. 저장 프로 시저에는 이전 드롭 다운 목록을 선택하는 매개 변수가 있습니다 (즉, 순서대로 실행해야 함). 이 기능을 구현하는 가장 좋은 방법은 무엇입니까? 나는 ASP MVC를 사용하고 있으며, 렌더링하기 위해 뷰 모델에 결과를 전달하는 데 어려움을 겪고있다.여러 저장된 Procs ASP MVC

답변

0

질문을 올바르게 이해했다면, 계단식 드롭 다운을 시도하고 있습니다. 그리고 저장 프로 시저를 사용하여 드롭 다운을 바인딩하고 있습니다. 좋아요 ??

다음은 예입니다. 두 개의 드롭 다운이 있습니다. 학교 및 코스. 학교에서 선택한 값을 변경하면 코스 드롭 다운의 값이 변경됩니다.

이 컨트롤러 :

public ActionResult SchoolList(int id) 
    { 
     IEnumerable<SelectListItem> schools = new Util().GetSchoolSelectList(id); 
     if (HttpContext.Request.IsAjaxRequest()) 
      return Json(schools, JsonRequestBehavior.AllowGet); 

     return View(schools); 
    } 

    public ActionResult CourseList(int id) 
    { 
     IEnumerable<SelectListItem> courses = new Util().GetCourseSelectList(id); 
     if (HttpContext.Request.IsAjaxRequest()) 
      return Json(courses, JsonRequestBehavior.AllowGet); 
     return View(courses); 
    } 

그리고 이것은 JQuery와 있습니다 :

$("#Schools").change(function() { 
     $.getJSON("/Account/CourseList/" + $("#Schools").val(), function (data) { 
      var items = "<option>Select your Course</option>"; 
      $.each(data, function (i, course) { 
       items += "<option value='" + course.Value + "'>" + course.Text + "</option>"; 
      }); 
      $("#Courses").html(items); 
     }); 
    }); 

그리고 이것은 HTML입니다 :

<select id="Schools" name="UserSchool"></select> 

<select id="Courses" name="UserCourse"></select> 
관련 문제