Getting default error message for int datatype
i.e he value 'abc' is not valid for age
What should i do.
public class HomeViewModel
{
[Integer(ErrorMessage="provide valid numeric value")}
public int age{ get; set; }
}
in your action method that you post data to ,did you check if the model is valid ?
[HttpPost]
public ActionResult MyActionMethod(Model model)
{
if(!ModelState.IsValid)
{
return View(model);
}
//else post data
}
if you want to display error message for the Integer you can try
[Required(ErrorMessage="Age Is Required")]
[Integer(ErrorMessage="Numbers Only")]
public int Age { get; set; }
[Integer] public int Age { get; set; } worksusing DataAnnotationsExtensions;