Chosenプラグインを使用しています。セクションドロップダウンリストを変更するときに、カテゴリ (選択済み) ドロップダウンリストを更新したい。
ここにビューがあります:
@model CategoryInputModel
@Html.DropDownListFor(model => model.SectionId, ViewBag.SectionList as IEnumerable<SelectListItem>, new { id = "SectionId" })
@Html.ListBoxFor(model => model.CategoryIdSet, ViewBag.AllCategoryList as MultiSelectList
, new
{
@class = "chzn-select",
data_placeholder = "Choose Categories...",
@style = "width : 500px;",
id = "CategoryIdSet"
})
CategoryInputModel は次のようなものです。
public class CategoryInputModel
{
public string Name { get; set; }
public int SectionId{ get; set; }
public List<int> CategoryIdSet{ get; set; }
}
単純なリストのカスケード ドロップダウン リストを作成できますが、複数選択用に作成できませんでした。私はこれを試しました:
<script type="text/javascript">
$(function () {
$("#SectionId").change(
function () {
loadLevelTwo(this);
});
loadLevelTwo($("#SectionId"));
});
function loadLevelTwo(selectList) {
var selectedId = $(selectList).val();
$.ajax(
{
url: "@Url.Action("GetCategoriesBySectionId", "Project")",
type: "GET",
data: { id: selectedId },
success: function (data) {
$("#CategoryIdSet").html($(data).html());
},
error: function (xhr) {
alert("Something went wrong, please try again");
}
});
}
</script>
コントローラーで:
public ActionResult GetCategoriesBySectionId(int id)
{
var result = MyService.GetCategoriesBySectionId(id);
// **its problem to create partial view that return chosen dropdownlist I need**
}
カスケードのChosenドロップダウンリストを作成するにはどうすればよいですか?