title: MVC4: Display jQuery model popup in view when error occurred?
body: <p>I am trying show a jQuery model popup when error occurred in controller and display a same view where controller trying return. </p>
  
  <p>Now I working on  <code>Home/Index.cshtml</code> and controller <code>[HttpGet] Index()</code> controller method. If any error occurred in Index() method display jQuery popup in view Index.cshtml.</p>
  
  <p>How can we do that?</p>
  
  <h2>Update</h2>
  
  <p>As <code>@MelanciaUK</code>, I have implemented like this.</p>
  
  <pre><code>  @{
          if (!String.IsNullOrEmpty(ViewBag.errorsOccurred))
          {
             &lt;text&gt;
                &lt;script type="text/javascript"&gt;
                    $(function () {
                        $.fancybox.open({
                                'content' : $("#divForm").html()
                     });
                  });
                &lt;/script&gt;
              &lt;/text&gt;
           }
        }
         @using (Html.BeginForm())
         {
                            ----
                            ----
         }
          &lt;div id="divForm" style="display:none"&gt;
              An error has occurred on the page.
          &lt;/div&gt;
  
      @section Scripts {  
       @Scripts.Render("~/bundles/fancybox")
      }
  </code></pre>
  
  <p><code>.fancybox.open</code> is never called and skipping from the executing in <code>@using (Html.BeginForm())</code>. I just want show <code>fancybox</code>. What was the wrong here?</p>