I have the following code.
try
{
if (vm.SubmitAction == "Cancel")
return RedirectToAction("ShowSummary", new
{
ds = vm.Meta.DataSourceID
}); <------------------------------------------- xxxx
_account.ValidateNoDuplicate(vm.Account);
vm.Account.Modified = DateTime.Now;
vm.Account.ModifiedBy = User.Identity.Name;
_account.AddOrUpdate(vm.Account);
}
catch (Exception e) {
log(e); return View("CreateEdit", vm);
}
return RedirectToAction("ShowSummary", new {
ds = vm.Meta.DataSourceID
});
If the user hits the cancel button then I have code ( Marked here with <– xxxx ) that redirects to an action. This code is the same as the code after the try block. Is there a way that I can make my code exit from the try. The only way I can think of is to trigger an exception and I want a clean jump and not one that uses the exception as it’s not an error for a user to click cancel.
Switch the if block condition around: