Tuesday, November 7, 2017

MVC Remote Validation

[Required]
[Display(Name = "Name")]
[StringLength(50, MinimumLength = 2, ErrorMessage = "Min 2 - Max 50 Characters only.")]
[Remote("CheckDuplicateName", "Employee", AdditionalFields = "EmpId,DeptId", ErrorMessage = "Name Already Exists.")]
[DisplayFormat(HtmlEncode = true)]
public string CName { get; set; }




[CustomAuthorize]
public JsonResult CheckDuplicateName()
{
var Ename = Request.QueryString[0];
var EId = Request.QueryString[1].ToInt();
var DId = Request.QueryString[2].ToInt();
var res = EmpBL.CheckDuplicateName(EnameEIdDId);

return Json(res, JsonRequestBehavior.AllowGet);
}

public static bool CheckDuplicateName(string Name, int? EmpId, int deptId)
{
bool isunique = true;

var deptId = TraBL.GetdeptId(deptId);

var cName = Name.Replace(System.Environment.NewLine, string.Empty).ToLower().Trim();

using (var entity = new ACDataEntities())
{
var result = (from c in entity.Employees
where c.deptId == deptId
&& c.tbl_Dept.DNAME.ToLower().Trim() ==  Name

select c).FirstOrDefault();

if (result != null)
{
isunique = false;
}
}

return isunique;

}

No comments:

Post a Comment

javascript Filter/index off

 var family = [{"name":"Jack",  "age": 26},               {"name":"Jill",  "age"...