查看
$('#frmCreateNewAdminPanelMenu').bootstrapValidator({
message: '.......',
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
txtMenuName_Create: {
validators: {
notEmpty: {
message: '......'
},
stringLength: {
min: 6,
max: 100,
message: '.......'
},
remote: {
type: 'POST',
url: '/AdminPanelMenu/MenuNameRemote',
message: 'Menu name is not available.',
delay: 1000
}
}
}
}
});
在此bootstrapvalidator处,传递txtMenuName_Create以检查是否存在。
CONTROLLER
public JsonResult MenuNameRemote(string txtMenuName_Create)
{
List<AdminPanelMenu> adminMenus = _adminPanelMenuRepo.GetAll().ToList();
return Json(adminMenus.Any(x => x.Name.ToLowerInvariant().Trim() == txtMenuName_Create.ToLowerInvariant().Trim()), JsonRequestBehavior.AllowGet);
}
在此控制器上,选中txtMenuName_Create后,将返回true或false数据。但是,我不知道如何将这些数据从控制器传递到视图。
答案 0 :(得分:0)
我终于解决了这个问题。
public JsonResult MenuNameRemote(string txtMenuNameRemote)
{
List<AdminPanelMenu> adminMenus = _adminPanelMenuRepo.GetAll().ToList();
if (adminMenus.Any(x => x.Name.ToLowerInvariant().Trim() == txtMenuNameRemote.ToLowerInvariant().Trim()))
return Json(new { valid = false });
else return Json(new { valid = true });
}