I have a grid that has defined defined CRUD operations on it. I am using the built-in Exception middleware to handle errors. However, the error page is not displayed when the controller's CREATE method throws an exception. However, the error page is displayed when an exception is thrown from the READ method. How do I force the CREATE controller to display the error page. Below is my code:
<div class="col-md-4 col-md-offset-4">
<ej-grid id="grd" allow-filtering="true" allow-paging="true" enable-header-hover="true" allow-sorting="true">
<e-edit-settings allow-adding="true" allow-editing="true"/>
<e-toolbar-settings show-toolbar="true" toolbar-items='@new List<string> {"add","edit","update","cancel"}' />
<e-datamanager json="@Model" insert-url="/Home/Create" update-url="/Home/Update" adaptor="remoteSaveAdaptor" />
<e-columns>
<e-column header-text="Id" field="Id" is-primary-key="true" is-identity="true" visible="false" />
<e-column header-text="Name" field="Name" />
</e-columns>
</ej-grid>
</div>
<ej-grid id="grd" allow-filtering="true" allow-paging="true" e-actionFailure="actionFailure" //action failure evnt
enable-header-hover="true" allow-sorting="true">
<e-datamanager json="@Model" insert-url="/Home/Create" update-url="/Home/Update" adaptor="remoteSaveAdaptor" />
<e-columns>
……….
</e-columns>
</ej-grid>
<script>
function actionFailure(args) {
}
</script> |
public class HomeController : Controller
{
public IActionResult Read()
{
throw new Exception("Test bad request.");
public ActionResult Create([FromBody] CRUDModel<MyType> myObject)
{
throw new Exception("Test bad request.”)//call the action Failure event of the grid
}
} |
<ej-grid id="grd" allow-filtering="true" allow-paging="true" e-actionBegin="actionbegin" //action begin
enable-header-hover="true" allow-sorting="true">
<e-datamanager json="@Model" insert-url="/Home/Create" update-url="/Home/Update" adaptor="remoteSaveAdaptor" />
<e-columns>
……….
</e-columns>
</ej-grid>
<script>
function actionbegin(args) {
if (args.requestType == "save") {
args.cancel = true;//cancel the default ajaxpost
var data = []; // create array here
$.each(args.data, function (index,value) {
data.push(value); //push values here
});
var formlength = $(".e-field").length;
for (i = 0; i < formlength; i++) {
$(".e-field").eq(i).attr('value',data[i]);//assign the all values to the form elements
}
$("#GridEditForm").attr({ action: "/Home/Create ", method: "POST" });
$("#GridEditForm").submit();//call the formpost
}
}
</script> |
public class HomeController : Controller
{
public IActionResult Read()
{
throw new Exception("Test bad request.");
public ActionResult Create([FromBody] CRUDModel<MyType> myObject)
{
.
.
.
throw new Exception("Test bad request.”)//exception
}
} |