Reputation: 25
I'm facing 2 issues while learning remote validation. First is that the values of int are being passed individually (e.g 123 being passed like 1 and 2 being sent in the next call). The second issue I'm facing is that each call is running twice in the controller. Here is the code of my model.
//Model
[Remote("CheckPhoneNum", "Employee", ErrorMessage = "Phone Number Must Start With 03 And Should Contain 11 Digits")]
[Required(ErrorMessage = "Please Enter Mobile No")]
[Display(Name = "Contact Number")]
[DataType(DataType.PhoneNumber)]
public int Mobile { get; set; }
View Code:
<div class="form-group">
@Html.LabelFor(model => model.Mobile, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.Mobile, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Mobile, "", new { @class = "text-danger" })
</div>
</div>
And my controller:
public JsonResult CheckPhoneNum(int Mobile)
{
string number = Convert.ToString(Mobile);
if (number.Substring(0,1).Equals("0") && number.Substring(1,2).Equals("3") && number.Length==11)
return Json(true,JsonRequestBehavior.AllowGet);
return Json(false, JsonRequestBehavior.AllowGet);
}
Any help will be greatly appreciated
Upvotes: 0
Views: 82