I am trying to use Remote validation in my application to check already exists record.
Here:
[Required(ErrorMessage = "*")]
public Nullable<long> fk_Store_ID { get; set; }
[System.Web.Mvc.Remote("doesGround", "User", HttpMethod = "POST", ErrorMessage = "Ground Level is already exists for this store.", AdditionalFields = "fk_Store_ID")]
[DefaultValue(false)]
public bool MembershipGroundLevel { get; set; }
and my controller action:
[HttpPost]
public JsonResult doesGround(bool MembershipGroundLevel, long? fk_Store_ID)
{
Int64 store_id = Convert.ToInt64(fk_Store_ID);
var count = db.tbl_Membership
.Where(o => o.fk_Store_ID == store_id && o.MembershipGroundLevel == true && o.isVisible == true).Count();
return count >= 1 ? Json(false, JsonRequestBehavior.AllowGet) : Json(true, JsonRequestBehavior.AllowGet);
}
Here I am getting NULL value for both. If I change datatype to bool and long respectively. I am getting internal server 500 error
I think your action
doesGround
definition is wrong, please try following oneIt is also good to ask if your validation
UserController
controller is inArea
, it yes, you need to specify area name inRemoteAttribute
deffinition byRoutData
property.