Grid View for ASP.NET MVC - How to implement client-side unobtrusive validation using a custom attribute
Follow the steps below to implement unobtrusive client-side validation:
- Create a ValidationAttribute class descendant.
- Implement the IClientValidatable interface for this class to enable client validation.
- Write a custom adapter based on custom parameters that are passed from the server.
- Add a custom validation method.
Wrap the Grid View extension in a <form> element that can be rendered with Html.BeginForm(). Validation scripts will be automatically registered on a callback.
@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { id = "frm" })) {
@Html.Action("GridViewPartial")
}- HomeController.cs (VB: HomeController.vb)
- CustomAttribute.cs (VB: CustomAttribute.vb)
- Person.cs (VB: Person.vb)
- _GridViewPartial.cshtml
- Index.cshtml
(you will be redirected to DevExpress.com to submit your response)