前端下拉复选框的使用(这里只有讲述新增时获取值以及查看详情时对他进行赋值)...

实现效果:

导入js以及css:

html代码:

js代码:

判断是否为空:

//途径省份
var rName = $(".ltlRegionName").val();
$(".ltlRegionName2").empty();
if (rName == null) {
$(".ltlRegionName2").append("<img src='/Images/validateFalse.png'/> 不可为空!");
}

查看详情赋值:

 var selectedData = [];

selectedData = data.infoList[0].ltlRegionName.split(',');
select2WithData2(selectedData);//给下拉复选框赋值

 ef循环新增多个省份:

js:

$.ajax({
url: "/BaseInfoPage/add",
data: {
ltlId: $("#ltl_Id").val(),
ltlRegionName: $(".ltlRegionName").val()
},
type: "POST",
dataType: "JSON",
success: function (data) {
if (data > 0) {
layer.msg('添加成功!', { icon: 1, time: 1000 }, function () {
delMenuCookie("大件运输许可管理添加", "大件运输许可管理");
});
}
}
})

控制器:

/// <summary>
/// 新增多个省份信息
/// </summary>
/// <param name="ltlId"></param>
/// <param name="ltlRegionName"></param>
/// <returns></returns>
public ActionResult add(string ltlId, string[] ltlRegionName)
{
int result = 0;
try
{
//组装数据
List<string> IdLists = new List<string>();
if (ltlRegionName[0] != null)
{
for (int i = 0; i < ltlRegionName.Length; i++)
{
IdLists.Add(ltlRegionName[i].ToString());
}

}
result = large_util.Add(ltlId, IdLists);
}
catch (Exception)
{

throw;
}
return Json(result);
}

后台接口:

public int Add(string lId, List<string> Ids)
{
int result = 0;
try
{
LargeRegionRelation datas = null;
foreach (var item in Ids)
{
if (item != "")
{
string listId = item;
datas = new LargeRegionRelation
{
lr_ltlId = lId,
lr_RegionId = listId
};
using (cmEntities db = new cmEntities())
{
db.LargeRegionRelation.Add(datas);
db.SaveChanges();
result = 1;
}
}
else
{
result = 0;
}
}
return result;

}
catch (Exception)
{
throw;
}
}

转载于:https://www.cnblogs.com/-lile/p/11262439.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值