1. In the model, add attributes notation
[Required(ErrorMessage="name is required")]
public string Name { get; set; }
2. In the View, add the following before Html.BeginForm
<script src="../../Scripts/jquery.validate.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.validate.unobtrusive.min.js"
type="text/javascript"></script>
@{ Html.EnableClientValidation(); }
3. Also in the View, add validation message beside your TextBox
<div class="FormInput">
@Html.EditorFor(model => model.Name)
@Html.ValidationMessageFor(model => model.Name)
</div>
No comments:
Post a Comment