계단식 드롭 다운 목록을로드하는 방법 asp.net mvc3? 내가 어떻게 할 수 있니? 나는 이용하고있다 http://geekswithblogs.net/ranganh/archive/2011/06/14/cascading-dropdownlist-in-asp.net-mvc-3-using-jquery.aspxmvc 3 jquery를 사용하여 계단식 드롭 다운 목록을 채우는 방법?
나는 할 수 없다. mymistake 무엇입니까? LoadJobByCustomerId 메소드에 디버그 레드 포인트를 추가했습니다.
이
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/ChildSite.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Index
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<script type="text/javascript" src="../../Scripts/jquery-1.4.4.js">
$(document).ready(function() {
$("#ddlCustomers").change(function() {
var idColour = $(this).val();
$.getJSON("/Job/LoadJobByCustomerId", { customerId: idColour },
function (modelData) {
var select = $("#ddlJobs");
select.empty();
select.append($('<option/>', {
value: 0,
text: "Select a Colour"
}));
$.each(modelData, function (index, itemData) {
select.append($('<option/>', {
value: itemData.Value,
text: itemData.Text
}));
});
});
});
</script>
<%
using (Html.BeginForm())
{ %>
<table style="padding:25px; margin:10px 10px 10px 10px;" id="sample">
<tr><td>Customer Name: </td><td>
<%= Html.DropDownList("Customers", null, "** Please Select **", new { id="ddlCustomers"})%>
</td></tr>
<tr><td>Job Name:</td><td>
<%= Html.DropDownList("Jobs", null, "** Please Select **", new { id = "ddlJobs" })%>
</td></tr>
</table>
<br />
<div>
</div>
<%}%>
</asp:Content>
컨트롤러 :
우선 들어
public class JobController : Controller
{
public ActionResult Index()
{
ViewData["Customers"] = new SelectList(CustomerOperation.GetCustomers().Items, "Id", "Name", null);
ViewData["Jobs"] = new SelectList(JobOperation.GetCustomersAssemblyList().Items, "scheduleId", "name", null);
return View();
}
[AcceptVerbs(HttpVerbs.Get)]
public JsonResult LoadJobByCustomerId(int customerId)
{
var jobs = JobOperation.GetCustomersAssemblyList(customerId).Items;
var jobItems = jobs.Select(c => new SelectListItem()
{
Text = c.name,
Value = c.scheduleId.ToString()
});
return Json(jobItems, JsonRequestBehavior.AllowGet);
}