I am working on an ASP .net MVC project in which I am using data annotation validator and it is not working. I am new to MVC .Please help me on this
My Model
public class Home { public int i; [Required(ErrorMessage="Please enter")] [StringLength(160)] public string name; } My Controller
public ActionResult Index() { Home h = new Home(); return View(h); } [HttpPost] public ActionResult Index(Home h) { if (ModelState.IsValid) { return RedirectToAction("Success"); } //ModelState.AddModelError("name", "Enter name"); return View(h); } My View
@using (Html.BeginForm()) { <label for="name">Name: </label> @Html.TextBoxFor(m=>m.name) @Html.ValidationMessageFor(m=>m.name) <input type="submit" value="Register" /> }