vs2013+MVC3.0+EasyUI的ComboBox联动使用(一)
2014-04-21 10:11
260 查看
vs2013+MVC3.0+EasyUI的ComboBox联动使用(一)
简介:在vs2013(.net4.0)中使用MVC3.0对于EasyUI中ComboBox的联动使用,
加载ComboBox数据,并且实现多级联动效果。
先说下样例所需的几个架构层,如图:
-----------------------------------------------------------------------------------------------------------------------------------------------------
下面主要展现3个实用模块的代码:
Controller:
-----------------------------------------------------------------------------------------------------------------------------------------------------
Pub:
-----------------------------------------------------------------------------------------------------------------------------------------------------
Biz:
vs2013+MVC3.0+EasyUI的ComboBox联动使用(一)
简介:在vs2013(.net4.0)中使用MVC3.0对于EasyUI中ComboBox的联动使用,
加载ComboBox数据,并且实现多级联动效果。
先说下样例所需的几个架构层,如图:
-----------------------------------------------------------------------------------------------------------------------------------------------------
下面主要展现3个实用模块的代码:
Controller:
/// <summary> /// 获取可用快递公司信息 /// </summary> /// <returns></returns> /// <remarks>创建人员(日期):★彭振★(140408 17:51)</remarks> public ActionResult GetExpressCorp() { ISale_outerListService ser = Sale_outerListService.Instance; //json string json = string.Empty; try { //获取可用快递公司信息 DataSet ds = ser.GetExpressCorp(); System.Data.DataTable dt = ds.Tables[0]; if (ds != null && ds.Tables.Count > 0) { dt = ds.Tables[0]; } else { return Content(json); } if (dt != null && dt.Rows.Count > 0) { List<dynamic> list = new List<dynamic>(); foreach (System.Data.DataRow dr in dt.Rows) { list.Add(new { ID = dr["ExpressCorpID"].GetString(), Name = dr["ExpressCorp"].GetString() }); } //2 查出数据 转 json json = list.ToJsonSerialize(); } else { return Content(json); } } catch (Exception ex) { json = string.Empty; } //3 输出 return Content(json); } /// <summary> /// 获取可用快递公司模板 /// </summary> /// <param name="parentId"></param> /// <returns></returns> ///<remarks>创建人员(日期):★彭振★(140408 18:00)</remarks> public ActionResult GetPrintTemplate(string parentId) { ISale_outerListService ser = Sale_outerListService.Instance; //json string json = string.Empty; try { //获取可用快递公司模板 DataSet ds = ser.GetPrintTemplate(parentId); System.Data.DataTable dt = ds.Tables[0]; if (ds != null && ds.Tables.Count > 0) { dt = ds.Tables[0]; } else { return Content(json); } if (dt != null && dt.Rows.Count > 0) { List<dynamic> list = new List<dynamic>(); foreach (System.Data.DataRow dr in dt.Rows) { list.Add(new { TemplateId = dr["TemplateId"].GetString(), TemplateName = dr["TemplateName"].GetString(), ExpressId = dr["ExpressCorpID"].GetString() }); } //2 查出数据 转 json json = list.ToJsonSerialize(); } else { return Content(json); } } catch (Exception ex) { json = string.Empty; } //3 输出 return Content(json); }
-----------------------------------------------------------------------------------------------------------------------------------------------------
Pub:
<table width='100%' border='0' cellpadding='0' cellspacing='1' id='editorScan' class='tbl-editor'> <tr> <td class="tbl-label">快递公司</td> <td class="tbl-value"> <input type="text" id="ExpressCorp" name="ExpressCorp" class="inp-normal" panelheight="100" /> </td> </tr> <tr> <td class="tbl-label">运单模板</td> <td class="tbl-value"> <input type="text" id="Templates" name="Templates" class="inp-normal" panelheight="100" /> </td> </tr> </table>
-----------------------------------------------------------------------------------------------------------------------------------------------------
Biz:
<script language="javascript"> //所有快递公司模板 dataset807 = @Html.Action("GetPrintTemplate", "Pack", new { parentId = 12 }) combobox807 = { valueField: 'TemplateId', textField: 'TemplateName', data: [], required: true, editable: false }; //所有快递公司 dataset806 = @Html.Action("GetExpressCorp", "Pack") combobox806 = { valueField: 'ID', textField: 'Name', data: dataset806, required: true, editable: false, fieldRelation: [{ 'ID': "ExpressCorpID" }, { 'Name': "ExpressCorp" }], onChange: function (newValue, oldValue) { $('#Templates').combobox('clear'); if (!dataset807) return; var newDateset=new Array(); for (var i=0 ; i < dataset807.length; i++) { var item = dataset807[i]; if (item.ExpressId == newValue) newDateset.push(item); } if (!newDateset) return; $('#Templates').combobox('loadData', newDateset); } }; $(function () { $('#Templates').combobox(combobox807); $('#ExpressCorp').combobox(combobox806); }); </script>
相关文章推荐
- vs2013+MVC3.0+EasyUI的ComboBox联动使用(二)
- vs2013+MVC3.0+EasyUI的ComboBox联动使用(二)
- jQuery-easyUI的使用:combobox实现联动选择及自动搜索
- VS2013 bug : 无法使用std::function包装成员函数
- 解决vs2013 MFC工程不能使用多字符集
- 【FFMEPG】windows下编译ffmpeg2.5——使用VS2013,ARMLINUX,ANDORID编译ffmpeg
- VS2013的一些配置、调试、使用
- 在windows下使用vs2013编译和调试mysql源代码
- VS 2013 win32控制台应用程序 动态链接库的导出与使用实例
- 在VS 2010中使用 VS2013的解决方案
- 使用VS2013自带的PreEmptive Dotfuscator and Analytis来混淆C#代码
- 有关巨硬vs2013使用心得
- vs2013 使用string,struct,指针
- 使用vs2013编译时遇到error msb3073 vcend exited with code 1
- jquery.easyui的ComboBox使用
- VS2013 中使用GDI+
- VS2013添加使用lib的方法
- PCL例程使用CMake导入VS2013失败
- Image watch +vs2013 配置和使用