MVC DropDownList 利用Ajax联动
来源:互联网 发布:淘宝巨型猪笼草 编辑:程序博客网 时间:2024/04/27 02:06
页面代码:
- <td style="text-align: right; width: 100px;">
- 城市/区域:
- </td>
- <td style="width: 170px; text-align: left">
- <%= Html.DropDownListFor(m => m.City, new SelectList(Test.TestPersistence.TestDao.GetCodeDict(11), "Id", "Name"))%>
- <%= Html.DropDownListFor(m => m.Region, new SelectList(Test.TestPersistence.TestDao.GetCodeDict(1001), "Id", "Name"))%>
- </td>
javascript代码:ajax的
- <mce:script type="text/javascript"><!--
- $(document).ready(function() {
- $("#City").change(function() {
- var selec = $("#City").val();
- $("#Region").get(0).options.length = 0;
- $.getJSON("RegionByCity?pid=" + selec, { 'City': selec }, function(data) {
- for (var i = 0; i < data.length; i++) {
- $("#Region").append("<option value='" + data[i].Id + "'>" + data[i].Name + "</option>");
- }
- });
- });
- });
- // --></mce:script>
control的代码:
- public ActionResult RegionByCity()
- {
- int pid = Convert.ToInt32(Request.QueryString["pid"]);
- CodeDao codeDao = new CodeDao();
- var codeList = codeDao.GetCodes(pid);
- if (Request.IsAjaxRequest())
- {
- return Json(codeList, JsonRequestBehavior.AllowGet);
- }
- else
- {
- return View("");
- }
- }
逻辑层:
- public IList<Code> GetCodes(int pid)
- {
- using (ISession session = sessions.OpenSession())
- {
- IQuery query = session.CreateQuery("from Code c where c.PId =:pid order by Id ");
- query = query.SetInt32("pid", pid);
- return query.List<Code>();
- }
- }
- MVC DropDownList 利用Ajax联动
- MVC DropDownList 利用Ajax联动
- Mvc Ajax Dropdownlist 联动实现
- MVC 利用Ajax联动
- MVC dropdownlist二级联动
- ajax实现DropDownList 联动
- MVC里面两个dropdownlist联动
- ajax无刷新联动DropDownList
- ajax dropdownlist无刷新联动
- Jquery ajax xml dropdownlist 联动
- ajax extension 实现dropdownlist 无刷 联动
- ajax实现无刷新两级联动DropDownList
- AJAX PRO 实例应用 DropDownList 联动
- 局部刷新AJAX的用法。DropDownList联动
- AJAX实现DropDownList无刷新二级联动
- DropDownList无刷新ajax二级联动效果
- yii2 利用dropDownList组件实现三级联动
- 用AJAX实现联动下拉菜单(Cascading DropDownList Using AJAX)
- JAVA基础:JAVA代码编写的30条建议
- ExtJs 常用代码片段(7.30更新)
- 排序算法总结
- 360极速浏览器之所以极速的另一可能原因——窗口
- oracle数据库常用SQL语句(11.11更新)
- MVC DropDownList 利用Ajax联动
- IDEA调试javaScript
- JavaScript中的eval()函数
- ExtJs 4 中的MVC应用架构
- GitHub Pages 搭建流程-基于jekyll-bootstrap
- CADisplayLink
- 关于使用curl 调用其他工程方法
- android经典DEMO
- Eclipse设置Instance variable的前缀