Topic: Validate Grid Data in ASPNET MVC
I have created an editable WebGrid in ASP.NET MVC 4 through which I will be able to edit, delete and update the data in the grid itself.
But I can't validate data in edit row in WebGrid.
I tried to search posts, without any result either, maybe I didn't use the right words.
How to do resolve this?
My code is shown below:
View
@model IEnumerable
@{
Layout = null;
WebGrid webGrid = new WebGrid(source: Model, canPage: true, canSort: false);
}
Index
@webGrid.GetHtml( htmlAttributes: new { @id = "WebGrid", @class = "Grid" }, columns: webGrid.Columns( webGrid.Column(header: "Customer Id", format: @@item.CustomerId, style: "CustomerId" ), webGrid.Column(header: "Name", format: @@item.Name , style: "Name"), webGrid.Column(header: "Country", format: @@item.Country , style: "Country"), webGrid.Column(format:@ Edit Update Cancel )))
Author: PADMAKEECHU
PARTH
It is up to you to define how the validation works. MVC comes with model validation. All you have to do is add standard validation annotations to the model definitions. Then do something when the model is not valid on the server.
There's also the standard unobtrusive validation which comes with MVC for which you can refer the below URL -
https://exceptionnotfound.net/asp-net-mvc-demystified-unobtrusive-validation/