Procs ASP MVC ที่เก็บไว้หลายรายการ

ฉันกำลังสร้างเพจที่ใช้ขั้นตอนการจัดเก็บหลายขั้นตอนเพื่อเติมรายการแบบหล่นลง กระบวนงานที่เก็บไว้มีพารามิเตอร์ที่เป็นตัวเลือกของรายการแบบเลื่อนลงก่อนหน้า (เช่น จำเป็นต้องดำเนินการตามลำดับ) วิธีที่ดีที่สุดในการใช้ฟังก์ชันนี้คืออะไร? ฉันใช้ ASP MVC และกำลังประสบปัญหาในการส่งผลลัพธ์ไปยังโมเดลมุมมองเพื่อเรนเดอร์อีกครั้ง


person Tui Popenoe    schedule 15.01.2013    source แหล่งที่มา


คำตอบ (1)


หากฉันเข้าใจคำถามของคุณถูกต้อง แสดงว่าคุณกำลังพยายามมีเมนูแบบเลื่อนลงแบบเรียงซ้อน และคุณกำลังผูกดรอปดาวน์ของคุณโดยใช้ Stored Procedures.. ใช่ไหม??

นี่คือตัวอย่าง: ฉันมีเมนูแบบเลื่อนลงสองรายการ โรงเรียนและหลักสูตร เมื่อคุณเปลี่ยนค่าที่เลือกในโรงเรียน เมนูแบบเลื่อนลงของหลักสูตรจะเปลี่ยนค่า

นี่คือตัวควบคุม:

 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>
person Crime Master Gogo    schedule 15.01.2013