In jQuery I have the following function:
function submitInventoryModal(unitFinancialCalendarId) {
const invoiceForm = $('form#submittalForm');
const formData = invoiceForm.serialize();
$.post('/Inventory/SaveInventorySubmittal', formData)
.success(function (response) {
debugger;
console.log(response);
viewSubmitConfirmation(unitFinancialCalendarId);
removeNavigationModalRequirement();
});
}
In SaveInventorySubmittal
the code has been implemented as:
[HttpPost]
[Authorize]
public async Task<IActionResult> SaveInventorySubmittal(InventorySubmittalBE inventorySubmittal)
{
try
{
RsiAsyncResult saveResult = await _inventoryService.SaveInventorySubmittalAsync(inventorySubmittal);
if (!saveResult.Succeeded)
return RedirectToAction("Message", Strings.Home,
new { Heading = "Error Saving Inventory Submittal", Message = "Invalid GL Configuration", SubMessage = saveResult.GetErrorString(), Icon = "user-times" });
Logger.LogInformation($"Inventory Submittal with UnitInventorySubmittalId: {inventorySubmittal.UnitInventorySubmittalId} saved successfully.");
return RedirectToAction("Index");
}
catch (Exception ex)
{
LogException(ex);
return RedirectToException(ex);
}
}
In this above method SaveInventorySubmittal
, an exception is thrown from the _inventoryService
, but the catch blocks return the RedirectToExceptiion
, which doesn't throw the exception and also is supposed to be redirected to the error page (Message view). But that doesn't happen.
The RedirectToException
method is implemented as:
protected RedirectToActionResult RedirectToException(Exception exception)
{
LogException(exception);
// If it's an RSI Exception, display the message
RsiException rsiException = exception as RsiException;
if (rsiException != null)
{
return RedirectToAction("Message", Strings.Home, new
{
Heading = "Error",
Message = rsiException.DisplayMessage,
SubMessage = ErrorSubMessage,
Icon = "bomb"
});
}
// For non-RSI exceptions, display something generic
return RedirectToAction("Message", Strings.Home, new
{
Heading = "Error",
Message = "We're sorry. An unexpected error has occurred.",
SubMessage = ErrorSubMessage,
Icon = "bomb"
});
}
Due to this implementation, the redirects never happens from the submitInventoryModal
in jQuery.
I wanted to redirect to the "Message" view, but the ajax code just goes into its own flow. How should I do the redirect?