Remote Validation in mvc not working

304 views Asked by At

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

1

There are 1 answers

1
Marcin On

I think your action doesGround definition is wrong, please try following one

public JsonResult doesGround(bool MembershipGroundLevel, long? fk_Store_ID)

It is also good to ask if your validation UserController controller is in Area, it yes, you need to specify area name in RemoteAttribute deffinition by RoutData property.