Note that there are some explanatory texts on larger screens.

plurals
  1. POJQuery AJAX HandleErrorAtribute PartialView
    primarykey
    data
    text
    <p>I have a function that submits a form to a MVC controller as follows - </p> <pre><code>function submitForm() { $.ajax ({ type: 'POST', url: '/Users/Index', data: $('#searchForm').serialize(), beforeSend: function() { $('.usersearchresult').fadeOut('fast', function () { $('.loadinggif').show(); }); }, success: function (response) { $('.loadinggif').hide(); $('.usersearchresult').hide().html(response).fadeIn('normal'); }, error: function (response) { alert(response); $('.loadinggif').hide(); $('.usersearchresult').hide().html(response).fadeIn('normal'); } }); return false; } </code></pre> <p>I wanted a central location to catch errors so I have extended <code>HandleErrorAttribute</code> -</p> <pre><code>public class ClientExceptionAttribute : HandleErrorAttribute { private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); public override void OnException(ExceptionContext context) { Log.Error(context.Exception); context.ExceptionHandled = true; // Verify if AJAX request if (context.HttpContext.Request.IsAjaxRequest()) { // Use partial view in case of AJAX request var result = new PartialViewResult(); result.ViewName = "~/views/shared/error.ascx"; context.Result = result; } } } </code></pre> <p>The error view is very simple - </p> <pre><code>@model String @{ Layout = null; } &lt;div class="exception"&gt; &lt;img src="../Content/Graphics/warning.png" /&gt; &lt;br /&gt; &lt;div class="message"&gt;@(String.IsNullOrEmpty(Model) ? "User Entry Api is currently unavailable" : Model) &lt;/div&gt; &lt;/div&gt; </code></pre> <p>The problem is that AJAX on error never renders the partial view (error.cshtml) - it just gives me a blank screen.</p> <p>So I have two questions -</p> <ol> <li>How do I make AJAX render the partial error view</li> <li>How can I pass a model to a partial view in the <code>ClientExceptionAttribute</code> </li> </ol> <p>Thank you!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload