|
public void Remove([FromBody]CRUDModel<OrdersDetails> Value)
{
if (Value.KeyColumn == "OrderID")
{
throw new Exception("Value cannot be deleted");
}//created exception
var data = orders.Where(or => or.OrderID.Equals(Value.Key)).FirstOrDefault();
orders.Remove(data);
}
|
|
actionFailure(args) {
console.log(args.error[0].error.responseText.split("Exception:")[1].split("</div>")[0]);
} //get the error status |
|
|
|
public dataManager: DataManager = new DataManager({
adaptor: new CustomUrlAdaptor,
insertUrl: "Home/Insert",
removeUrl: "Home/Delete",
updateUrl: "Home/Update",
url: "Home/DataSource"
});
class CustomUrlAdaptor extends new UrlAdaptor {
// here we are overriding the default processresponse method of the UrlAdaptor adaptor
processResponse() {
// here you can able to check the response // calling base class processResponse function
var original = super.processResponse.apply(this, arguments);
// Data is returned in the below format to set it in the Grid properly while using UrlAdaptor, I if your data as empty you need to send result as [] and count as 0
return { result: original.result, count: original.count };
}
}
|
|
public dataManager: DataManager = new DataManager({
adaptor: new CustomUrlAdaptor,
insertUrl: "Home/Insert",
removeUrl: "Home/Delete",
updateUrl: "Home/Update",
url: "Home/DataSource"
});
class CustomUrlAdaptor extends new UrlAdaptor {
// here we are overriding the default processresponse method of the UrlAdaptor adaptor
processResponse() {
// here you can able to check the response // calling base class processResponse function
var original = super.processResponse.apply(this, arguments);
// Data is returned in the below format to set it in the Grid properly while using UrlAdaptor
return { result: original.result, count: original.count };
}
}
|
hi how can i handle internal server error when i throw exception msg. i am able to getting error msg but in console getting internal error. pls help
Hi Aman,
Before we start providing solution to your query, we need some information for
our clarification. So, please share the below details that will be helpful for
us to provide better solution.
1) Share your code example about how you are throwing the exception and how you are getting the error message.
2) Share your package version.
3) Share your complete Grid rendering code.
4) Share your issue scenario in video demonstration, we would like to check at what case you are throwing the exception
Regards,
Rajapandi R
when insert or update fail then we throw exception msg and pass this msg to action failure method . then msg show in alert popup.
.ClientSideEvents(eve => { eve.ActionFailure("Failure"); })
)
function
Failure(args) {
this.cancelEdit();
var
str =
"";
str = $(args.error.responseText).find('i').text();
alert(str);
}
public
ActionResult
Update(EditableOrder
value)
{
throw
new
Exception("TEST");
OrderRepository.Update(value);
var
data =
OrderRepository.GetAllRecords();
return
Json(data,
JsonRequestBehavior.AllowGet);
}
Hi Aman kumar,
Query: hi how can i handle internal server error when i throw exception msg. i am able to getting error msg but in console getting internal error
Based on your query, we understand that you prefer not to display error messages in the console, and you want to display an error message within a dialog. We achieved this requirement by using dialog component. In the actionFailure event, we prevent the console message, bind the error message into the dialog, and open the dialog to display the message.
Please refer to the below code example,
|
@{
Html.EJ() .Dialog("dialog") .Title("Dialog") .ShowOnInit(false)
.Render(); }
@(Html.EJ().Grid<Object> ("FlatGrid") .Datasource(http://mvc.syncfusion.com/Services/Northwnd.svc/Orders/) ….. .ClientSideEvents(eve=>{eve.ActionFailure("FailMessage");}) )
<script type="text/javascript"> var str; function FailMessage(args) { console.clear();//clear the console var error =args.error.statusText; //get the error message from server side. str = "<tr><td>" + error + "</td></tr>"; $('#dialog').html(""); $('#dialog').html("<table>" + str + "</table>"); $("#dialog").ejDialog("open"); } </script>
|
Please refer to the below screenshot,
Please refer to the below help documentation,
https://help.syncfusion.com/aspnetmvc/dialog/getting-started
If the above solution does not meet your requirement, kindly share the below details which is helpful to proceed further.
Kindly get back to us for further assistance.
Regards,
Farveen sulthana T
If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.