// PUT odata/Suppliers(5)
public IHttpActionResult Put([FromODataUri] int key, Order supplier)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
…
return Updated(supplier);
} |
columns: [
{ field: "OrderID",isPrimaryKey:true, headerText: 'Order ID', width: 90 },
{ field: "ShipCity",headerText: 'ShipCity', width: 90 },
{ field: "EmployeeID", headerText: 'EmployeeID', textAlign: ej.TextAlign.Right, width: 80 },
{ field: "OrderDate", headerText: "OrderDate", format: "{0:MM/dd/yyyy}", validationRules: { date: true }}
] |
actionFailure: function(args){
alert(args.error.statusText);//here we will get error message
},
………………….
public IHttpActionResult Post(Order supplier)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
db.Orders.Add(supplier);
db.SaveChanges();
return Created(supplier);
} |
Hi Andrea,
If you want to show the validation message in client side, then you need to set the validationRules property for the grid columns. Please refer to the below code example.
columns: [{ field: "OrderID",isPrimaryKey:true, headerText: 'Order ID', width: 90 },{ field: "ShipCity",headerText: 'ShipCity', width: 90 },{ field: "EmployeeID", headerText: 'EmployeeID', textAlign: ej.TextAlign.Right, width: 80 },{ field: "OrderDate", headerText: "OrderDate", format: "{0:MM/dd/yyyy}", validationRules: { date: true }}]If client side validation is enabled, first the data is validated at client side and only if it satisfies the criteria, the controller action is triggered.We can perform the server side validation and throw exception at controller when the validation fails which can be handled using ActionFailure event of the grid. Please refer to the below help document, code example and sample.
actionFailure: function(args){alert(args.error.statusText);//here we will get error message},………………….public IHttpActionResult Post(Order supplier){if (!ModelState.IsValid){return BadRequest(ModelState);}db.Orders.Add(supplier);db.SaveChanges();return Created(supplier);}
Regards,
Jayaprakash K.