Thread ID: |
Created: |
Updated: |
Platform: |
Replies: |
143686 | Apr 1,2019 08:52 AM UTC | Apr 4,2019 05:07 AM UTC | ASP.NET MVC - EJ 2 | 5 |
![]() |
Tags: Grid |
alert(args.error.statusText);
//get the exception message
[Client side code]
@Html.EJS().Grid("Grid").DataSource(ds => ds.Url("/Home/UrlDatasource").Adaptor("UrlAdaptor").InsertUrl("/Home/Insert")
.RemoveUrl("/Home/Remove").UpdateUrl("Home/Update")).AllowPaging(true).Columns(col =>
{
col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Width("120").Add();
...
}).Toolbar(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" }).ActionFailure("failure").EditSettings(edit => { edit.AllowAdding(true).AllowDeleting(true).AllowEditing(true); }).Render()
<script>
function failure(args) {
var errorMessage = args.error[0].error.responseText.split("Exception:")[1].split('<br>')[0]; //extract the message from args
alert(errorMessage);
}
</script>
[Server side code]
public ActionResult Insert(Orders value)
{
var data = order.Where(or => or.OrderID == value.OrderID).FirstOrDefault();
if (data == null)
{
order.Insert(0, value);
}
else
{
throw new Exception("Duplicate values cannot be inserted"); //Add custom exception message
}
return Json(value);
} |
This post will be permanently deleted. Are you sure you want to continue?
Sorry, An error occured while processing your request. Please try again later.
This page will automatically be redirected to the sign-in page in 10 seconds.