2
在嘗試更多級聯下拉之後,我決定通過Jquery來完成。如何讓Json對象下拉?
這是我cityController
public ActionResult States(int id)
{
AcademicERP.Models.AcademicERPDataContext dc = new AcademicERPDataContext();
var states = from s in dc.States
where s.CountryID == id
select s;
return Json(states.ToList());
}
,我試圖從
城市叫它/有腳本
var ddlCountry;
var ddlStateID;
function pageLoad() {
ddlStateID = $get("StateID");
ddlCountry = $get("CountryID");
$addHandler(ddlCountry, "change", bindOptions);
bindOptions();
}
function bindOptions() {
ddlStateID.options.length = 0;
var CountryID = ddlCountry.value;
if (CountryID) {
// some logic to call $.getJSON()
}
創建頁面,我有DD的意見
<%= Html.DropDownList("CountryID") %>
<select name="StateID" id="StateID"></select>
那麼什麼是getJSON參數? 我指的是blog。但不工作。
你也可以做到這一點而不必通過使用http://awesome.codeplex.com中的AjaxDropdown來了解/寫入jQuery實時演示:http://demo.aspnetawesome.com/AjaxDropdownDemo – Omu 2012-02-22 19:14:05