Global Fehlerbehandlung mit PartialView in MVC

Ich habe mir einen der perfekten Artikel auf @ angescha Ausnahmebehandlung in ASP.NET MVC und möchten eine Methode wie in Methode 6 in diesem Artikel implementieren, um dieselbe Fehlerseite für alle anderen modalen Dialogfelder in Fehler- und Ausnahmesituationen wiederzuverwenden. Wenn ich dagegen ein Popup-Fenster verwende, muss ich ein @ renderPartialView in meinem modalen Dialog, anstatt die Seite umzuleiten. Ist das möglich?

Ajax-Aufruf:

$.ajax({
    type: "POST",
    url: '@Url.Action("Delete", "Person")',
    cache: false,
    dataType: "json",
    data: formdata,

    success: function (response, textStatus, XMLHttpRequest) {
        if (response.success) {
            //display operation result
        }
        else {
            /* At this stage I need to render the Error view as partial without 
            redirecting to Error page on error. The problem at here not directly 
            related to rendering partialview. I need to render the global Error 
            page and reuse it for every error occured on my modal dialog */
            @Html.Partial("~/Views/Home/Error.cshtml", Model)
        }
    }
});

Regler

[HttpPost]
public JsonResult Delete(int id)
{
    try
    {
        //code omitted for brevity
    }
    catch (Exception  ex)
    {
        return Json(new { success = false, message = "Operation failed." });
    }
}

Antworten auf die Frage(0)

Ihre Antwort auf die Frage