Jquery选择的ajax调用填充multiselect无效
我正在使用Jquery Selected multiselectlist将事件添加到基于会议的列表中 在包含游泳和田径字符串的下拉列表中选择的运动类型。 当我选择游泳时,取消选择的列表中应该只有游泳项目可用 ,田径运动也是如此。Ajax对我来说有点新鲜,给我带来了一些问题。 如下图所示,列表中还有一个非田径项目 (100米蛙泳项目) 我正在使用MVC4和实体框架 下拉列表:Jquery选择的ajax调用填充multiselect无效,jquery,ajax,json,asp.net-mvc-4,Jquery,Ajax,Json,Asp.net Mvc 4,我正在使用Jquery Selected multiselectlist将事件添加到基于会议的列表中 在包含游泳和田径字符串的下拉列表中选择的运动类型。 当我选择游泳时,取消选择的列表中应该只有游泳项目可用 ,田径运动也是如此。Ajax对我来说有点新鲜,给我带来了一些问题。 如下图所示,列表中还有一个非田径项目 (100米蛙泳项目) 我正在使用MVC4和实体框架 下拉列表: @Html.DropDownListFor(model => model.Meeting.Regi
@Html.DropDownListFor(model => model.Meeting.RegionId, (IEnumerable<SelectListItem>)ViewBag.RegionId, "...")
@Html.ValidationMessageFor(model => model.Meeting.RegionId)
Ajax调用:
$("#Meeting_Sport").change(function () {
var _this = document.getElementById('Meeting_Sport');
var thisValue = _this.options[_this.selectedIndex].value;
$.getJSON("@Url.Action("GetEventsAjax")/" + _this.value, function (data) {
if (data.Status == "Success") {
var possibilities = "";
var items = "";
$.each(data.Events, function (index, item) {
possibilities += '<li id="' + 'select1_chzn_o_' + data.EventsId[index] + '" class="active-result style="">"' + item + '"</li>';
items += "<option value='" + data.EventsId[index] + "'>" + item + "</option>";
});
$(".chzn-results").children().remove().end();
$("#select1").children().remove().end();
$("#select1").html(items);
$(".chzn-results").html(possibilities);
$("label[for='input01']").show();
$("#input01").show();
$("#select1_chzn").show();
var items = "";
var possibilities = "";
}
});
})
$(“#会议(u运动”)。更改(功能(){
var_this=document.getElementById('Meeting_Sport');
var thisValue=\u this.options[\u this.selectedIndex].value;
$.getJSON(@Url.Action(“GetEventsAjax”)/“+\u this.value,函数(数据){
如果(data.Status==“成功”){
var可能性=”;
var项目=”;
$.each(data.Events,函数(索引,项){
可能性+='可能不是您出现问题的唯一原因,但在活动结果
之后,您缺少了一个双引号,“class=“active result style=”“>”
,这会破坏您的html啊,这确实是一个错误,但并没有解决问题:)控制台中是否有脚本错误?在操作中插入调试器中断符--操作是否返回正确的数据集?它返回正确的数据集
$("#Meeting_Sport").change(function () {
var _this = document.getElementById('Meeting_Sport');
var thisValue = _this.options[_this.selectedIndex].value;
$.getJSON("@Url.Action("GetEventsAjax")/" + _this.value, function (data) {
if (data.Status == "Success") {
var possibilities = "";
var items = "";
$.each(data.Events, function (index, item) {
possibilities += '<li id="' + 'select1_chzn_o_' + data.EventsId[index] + '" class="active-result style="">"' + item + '"</li>';
items += "<option value='" + data.EventsId[index] + "'>" + item + "</option>";
});
$(".chzn-results").children().remove().end();
$("#select1").children().remove().end();
$("#select1").html(items);
$(".chzn-results").html(possibilities);
$("label[for='input01']").show();
$("#input01").show();
$("#select1_chzn").show();
var items = "";
var possibilities = "";
}
});
})
[HttpGet]
public ActionResult GetEventsAjax(String id)
{
try
{
List<String> Events = db.Events.Where(e => e.Sport == id).Select(e => e.Name).ToList();
List<int> EventsId = db.Events.Where(e => e.Sport == id).Select(e => e.EventId).ToList();
return Json(new { Status = "Success", Events = Events, EventsId = EventsId }, JsonRequestBehavior.AllowGet);
}
catch (Exception e)
{
return Json(new { Status = "Failure", Message = e.Message });
}
}