项目中使用Bootstrapvalidator对某个字段的异步验证,验证时需要把另外一个字段的值传到后端联合查询数据库进行验证,发现后端始终接收不到传值,代码如下:
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
excluded: [':disabled'],
fields: {
txt_typeName: {
selector: '#txt_typeName',
validators: {
notEmpty: {
message: '请填写型号名称'
}
,
remote: {
message: '型号已存在',
url: '/Type/nameIsOnly',
type: "post",
dataType: "json",
data: {
brand: $('#hid_select_brand').val()
},
dalay: 500
}
}
}
},
submitHandler: function (validator, form, submitButton) {
validator.defaultSubmit();
}
})
后端代码
string brand = Request["brand"];
接收值始终未“”,后来查找资料和他人经验,发现remote的data传值时应改为function形式,代码
remote: {
message: '型号已存在',
url: '/Type/nameIsOnly',
type: "post",
dataType: "json",
data: {
brand: function () {
return $('#hid_select_brand').val()
},
name: function () {
return $('#txt_typeName').val();
}
},
dalay: 500
}