后端代码:
public ActionResult GetSNData(string PartNo)
{
string sql = string.Format(@" select SN from CuttingTools_ReceiptGoodsDetail where ToolState=N'待发' and PartNo='{0}' ", PartNo);
DataSet dsset = _service.QueryBySql(sql);
DataTable sum = dsset.Tables[0];
return Json(sum);
}
前端JS
function GetSelectData()
{
var PartNo = $("#_Dialog #PartNo").val();
// var SN = document.getElementById("SN");
// document.getElementById("SN").options.length = 0;//清空下拉菜单
$.ajax({
url:'@Url.Action("GetSNData")',
type: "post",
dataType: "json",
async: true,
data: { PartNo: PartNo },
success: function (data) {
// alert("123");
// debugger;
$("#SN").empty();
// $("#SN").append($('<option value="">请选择</option>'));
for (var i = 0; i < data.length; i++) {
// SN.options.add(new Option(data[i].SN, data[i].SN));
$("#SN").append($('<option value=' + data[i].SN + '>' + data[i].SN + '</option>'));
// alert(data[i].SN);
}
$("#SN").selectpicker('refresh');
$('.dropdown-toggle').dropdown();
$("#SN").trigger("click");
}
});
};
页面下拉框:
<select name="SN" ID="SN" class="form-control selectpicker" multiple="multiple"
id="SN" title="请选择"
@*data-actions-box="true"*@
@*data-live-search="true"*@>
<option value="">请选择</option>
</select>