Topic:   Validate Grid Data in ASPNET MVC
Jan 11, 2021 12:34 1 Replies 809 Views PADMAKEECHU

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 )))

Prev Next
Topic Replies (1)
  1. 1
    idnkx user

    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/

Leave a Reply
Guest User

Not sure what course is right for you?

Choose the right course for you.
Get the help of our experts and find a course that best suits your needs.


Let`s Connect