0
모델의 [원격] 데이터 주석을 사용하여 데이터베이스에있는 전자 메일 Id의 존재를 확인하고 싶습니다. 그러나 원격 JsonResult Action 메서드를 호출하면 매개 변수가 null이되고 결과는 항상 false가되며 오류 메시지가 표시됩니다. 내 코드의 문제점은 무엇입니까?[원격] 데이터 주석 속성을 사용하여 기존 전자 메일 ID의 유효성을 확인할 수 없음
모델 :
public class RegisterModel
{
[Required(ErrorMessage = "Email is Required!", AllowEmptyStrings = false)]
[Remote("IsEmailIdExists", "Account", ErrorMessage = "Email Id already exists in Database")]
[Display(Name = "Email Id")]
[RegularExpression("[A-Za-z0-9._%+-][email protected][A-Za-z0-9.-]+.[A-Za-z]{2,4}", ErrorMessage = "Invalid Email Id")]
public string Email { get; set; }
[Required(ErrorMessage = "Password is Required!", AllowEmptyStrings = false)]
[DataType(DataType.Password)]
[RegularExpression(@"(?=^.{8,15}$)((?=.*\d)(?=.*[A-Z])(?=.*[a-z])|(?=.*\d)(?=.*[^A-Za-z0-9])(?=.*[a-z])|(?=.*[^A-Za-z0-9])(?=.*[A-Z])(?=.*[a-z])|(?=.*\d)(?=.*[A-Z])(?=.*[^A-Za-z0-9]))^.*", ErrorMessage = "Invalid Password!")]
public string Password { get; set; }
[System.ComponentModel.DataAnnotations.Compare("Password", ErrorMessage = "Confirm password dose not match!")]
[Required(ErrorMessage = "Confirm Password is Required!")]
[DataType(DataType.Password)]
public string ConfirmPassword { get; set; }
}
public class EmailExists
{
public bool EmailCheck(string _email)
{
try
{
var con = new SqlConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString;
SqlCommand com = new SqlCommand("spCheckEmail", con);
com.CommandType = CommandType.StoredProcedure;
com.Parameters.Add("@uname", SqlDbType.NVarChar, -1).Value = _email;
con.Open();
com.CommandTimeout = 120;
SqlDataReader reader = com.ExecuteReader();
if (reader.HasRows)
{
if (reader.Read())
{
if (reader["Active"].ToString() == "True")
{
reader.Dispose();
com.Dispose();
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
else
{
reader.Dispose();
com.Dispose();
return false;
}
con.Close();
com.Dispose();
}
catch(Exception ex)
{
return false;
}
}
}
계정 컨트롤러
public JsonResult IsEmailIdExists(string EmailId) -> Always Null
{
Model.EmailExists emailCheck = new FresherModel.EmailExists();
if(!emailCheck.EmailCheck(EmailId))
{
return Json(false);
}
else
{
return Json(true);
}
}
완벽한 브로 .. Jus 약간의 실수로 인해 나에게 와서 .. :) 감사합니다. :) –