使用复选框
1.后台查询list
枚举类list: ViewBag.ListShopWeapp = typeof(EnumShopWeapp).EnumToDictionary();
查询类list:ViewBag.shopWeapps = _shopWeappSetting.GetList(n => n.ChainId == shopEntity.ChainId && n.ShopId == shopEntity.ID);
2.页面复选框
@foreach (var item in ViewBag.ListShopWeapp)
{
<div class="layui-col-xs3 layui-col-sm3 layui-col-lg3">
<input type="checkbox" name="cb-weapp" @(weapp.Any(a => a.WeappCategory == Convert.ToInt32(item.Value)) ? "checked" : "") lay-skin="primary" title="@item.Key" value="@item.Value">
</div>
}
</div>
</div>
3.js提交
1.首先页面需要获取到所有选中的值
window.getWeapps = function () {
var arr = new Array();
$(“input:checkbox[name=‘cb-weapp’]:checked”).each(function (i) {
arr[i] = $(this).val();
});
return arr.toString();
}
2.首页需要定义获取的值
beforeSubmit: function (d, i) {
d.field.IsNetWork = d.field.IsNetWork == ‘on’;
d.field.IsOffline = d.field.IsOffline == ‘on’;
d.field.IsGiveCoinExpProtect = d.field.IsGiveCoinExpProtect == ‘on’;
if (i.getWeapps) {
d.field.weapps = i.getWeapps();
}
}
3.控制器获取值
string weapps = this.Request.Params.Get(“weapps”);