MVC 联动 dropdowlist
来源:互联网 发布:免费云数据库mysql 编辑:程序博客网 时间:2024/05/01 12:27
前台:
@using (Html.BeginForm("AddressPost", "Address", FormMethod.Post, new { name = "frmAddressMgr", id = "frmAddressMgr" }))
{
<div>
收货地址 您已创建?个收货地址,最多可创建5个
<div>
<!--列表区-->
</div>
<div>
<!--添加修改区-->
添加收货地址
<hr/>
<table>
<tr>
<td>收货人:</td><td>@Html.TextBox("Receiver", Model.Receiver, new { @class="validate[required]"})<font color="red">*</font></td>
</tr>
<tr>
<td>地区:</td><td>@Html.DropDownList("provincesDDlItems")<font color="red">*</font> <select id="ddlCity" /></td>
</tr>
<tr>
<td>详细地址:</td><td>@Html.TextBox("DetailAddress",Model.DetailAddress,new { @class="validate[required]"})<font color="red">*</font></td>
</tr>
<tr>
<td>手机:</td><td>@Html.TextBox("Phone",Model.Phone)</td> <td>座机:</td><td>@Html.TextBox("LandLineAreaCode",Model.LandLineAreaCode)</td><td>-</td><td>@Html.TextBox("LandLine",Model.LandLine)手机和座机至少填写一个</td>
</tr>
<tr>
<td>电子邮箱:</td><td>@Html.TextBox("DetailAddress",Model.DetailAddress,new { @class="validate[required,custom[email]]"})<font color="red">*</font>用于接收订单状态信息</td>
</tr>
</table>
<div>
<input type="button" id="btnAdd" value="添加这个地址" />
</div>
</div>
</div>
<script type="text/javascript">
$(function () {
$("#frmAddressMgr").validationEngine();
$("#btnAdd").click(function () {
$('#frmAddressMgr').submit();
});
});
$("#provincesDDlItems").change(function () {
var provinceSelected = $("#provincesDDlItems").val();
$("#ddlCity").get(0).options.length = 0;
//$.post("/Address/GetCitys/" + provinceSelected, { 'province': provinceSelected }, function (data) {
// alert("getJson!");
// $.each(data, function (i, item) {
// $("<option></option>").val(item["CityID"]).text(item["CityName"]).appendTo($("#provincesDDlItems"));
// });
//}); (以后千万不要用这种方式,这种方式永远看不到错误信息!)
$.ajax({
type: 'POST',
url: '/Address/GetCitys/' + provinceSelected,
data : { 'provinceId': provinceSelected },
success: function (data) {
debugger;
$.each(data, function (i, item) {
$("<option></option>").val(item["CityID"]).text(item["CityName"]).appendTo($("#ddlCity"));
});
},
error: function (data) {
alert(data.responseText);
}
});
});
</script>
}
后台代码:
public ActionResult GetCitys() {
if (Request.IsAjaxRequest())
{
IList<Hashtable> citysList = this.userAddressBO.GetCitys<Hashtable>(int.Parse(Request.Form["provinceId"]));
return Json(citysList);
}
else {
return View("");
}
}
错误场景 public ActionResult GetCitys(int provinceId)
一个参数,导致前台ajax提交 没有任何反应! 以后一定要多加一个error回调监测,才是专业的表现。
- MVC 联动 dropdowlist
- 用简易Ajax框架实现DropDowList联动DataGrid绑定查询 效果的实现【原创】
- MVC 利用Ajax联动
- mvc 三级联动
- MVC + jQuery 三级联动
- MVC dropdownlist二级联动
- .net关于dropdowlist操作
- Mvc Ajax Dropdownlist 联动实现
- MVC DropDownList 利用Ajax联动
- MVC三级联动无刷新
- MVC DropDownList 利用Ajax联动
- MVC里面两个dropdownlist联动
- MVC实现类似省级联动
- 基于MVC的三级联动
- MVC二级联动使用$.getJSON方法
- 在mvc中用ajax实现省市联动
- select联动(C#+.NET MVC+Jquery)
- .net MVC 下拉多级联动及编辑
- Sql Server中sql语句自动换行
- ProgressBar
- 捉虫记录:OpenCV中的类型问题
- Leetcode【1】:Two Sum
- QT_PC学习_GUI程序设计入门
- MVC 联动 dropdowlist
- 什么时候我能见到你
- 尚学堂马士兵struts2 课堂笔记(三)
- Android应用初体验
- 3:jdbc 连接池,批处理,图片处理等
- PHP <?= Uri::base(false) ?> 无法解析
- 几个常用的javascript框架比较
- Struts2的web.xml(前端控制器的配置)
- C# 支付宝接口