View
<script>
$(document).ready(function () {
$('#txtmodel').combobox({
url: '/OMCS/CPK/DropDownModel',
valueField: 'text',
textField: 'text',
editable: true,
required: true,
mode: 'remote',
loadFilter: function (data) { return data.rows; },
onChange: function (record, old) {
var url = '/OMCS/CPK/DropDownMo?model=' + record;
$('#txtmo').combobox('reload', url);
},
});
$('#txtmo').combobox({
url: '/OMCS/CPK/DropDownMo?model=' + "",
valueField: 'text',
textField: 'text',
editable: true,
required: true,
mode: 'remote',
loadFilter: function (data) { return data.rows; },
})
});
</script>
<table style="margin: 15px;" >
<tr>
<td>Model:</td>
<td>
<input class="easyui-combobox" id="txtmodel" name="model" style="width: 90px; height: 25px;" />
</td> <td>
<input class="easyui-combobox" id="txtmo" name="mo" style="width: 120px; height: 25px;" />
</td> </tr></table>
後臺 public ActionResult MoSearch()
{
return View();
}
public JsonResult DropDownModel()
{
List<string> ModelList = new List<string>();
List<string> OneModel = new List<string>();
ModelList = dboqc.dbset_oqc.Select(o => o.Model).ToList();
foreach (var NN in ModelList)
{
if (!OneModel.Contains(NN))
{ OneModel.Add(NN); }
}
clsdropdown.Add(new _0.Models.ClsDropDownModel() { ID = 0, text = "" });
for (int _modelcount = 0; _modelcount < OneModel.Count; _modelcount++)
{
clsdropdown.Add(new _0.Models.ClsDropDownModel() { ID = _modelcount + 1, text = OneModel[_modelcount] });
}
var json = new
{
length = clsdropdown.Count,
rows = clsdropdown.ToArray(),
};
var onemodel = (from c in clsdropdown select new SelectListItem { Text = c.text, Value = c.text }).ToList();
List<SelectListItem> aaa = new List<SelectListItem>();
ViewData["model"] = onemodel;
ViewData["mo"] = aaa;
return Json(json, JsonRequestBehavior.AllowGet);
}
[HttpPost]
public JsonResult DropDownMo(string model)//在model選擇的情況下下拉出MO選項
{
var mollist=dboqc.dbset_oqc.Where(o => o.Model == model).Select(o=>o.MO).ToList();
List<string> oneMo = new List<string>();
var json = new Object();
foreach (var nn in mollist)
{
if (!oneMo.Contains(nn)) { oneMo.Add(nn); }
}
clsdropdown.Add(new _0.Models.ClsDropDownModel() { ID = 0, text = "" });
for (int _mocount = 0; _mocount < oneMo.Count; _mocount++)
{
clsdropdown.Add(new _0.Models.ClsDropDownModel() { ID = _mocount + 1, text = oneMo[_mocount] });
}
var mo = (from c in clsdropdown select new SelectListItem { Text = c.text, Value = c.text }).ToList();
if (mo.Count != 0)
{
json = new
{
length = clsdropdown.Count,
rows = clsdropdown.ToArray(),
};
}
return Json(json, JsonRequestBehavior.AllowGet);
}