Note that there are some explanatory texts on larger screens.

plurals
  1. POAjax.BeginForm(...) not always working, full postback sometimes, using ASP.NET MVC
    text
    copied!<p>I cannot for the life of me figure out why this postback <em>sometimes</em> does an ajax one as it is supposed to and sometimes it does not. Here is the relevant code:</p> <p>JS:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;Index&lt;/title&gt; &lt;link href="/Content/screen.css" rel="stylesheet" type="text/css" /&gt; &lt;!--[if lt IE 8]&gt;&lt;link href="/Content/ie.css" rel="stylesheet" type="text/css" /&gt;&lt;![endif]--&gt; &lt;link href="/Content/plugins/fancy-type/screen.css" rel="stylesheet" type="text/css" /&gt; &lt;link href="/Content/plugins/buttons/screen.css" rel="stylesheet" type="text/css" /&gt; &lt;link href="/Content/plugins/link-icons/screen.css" rel="stylesheet" type="text/css" media="screen, projection" /&gt; &lt;link href="/Content/jQueryUI/css/cupertino/jquery-ui-1.8.9.custom.css" rel="stylesheet" type="text/css" /&gt; &lt;link href="/Content/HelpDesk.css" rel="stylesheet" type="text/css" /&gt; &lt;link href="/Content/droppy.css" rel="stylesheet" type="text/css" /&gt; &lt;link href="/Content/tablesorter.css" rel="stylesheet" type="text/css" /&gt; &lt;script src="/Scripts/jquery-1.4.4.min.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="/Scripts/jquery-ui.min.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="/Scripts/jquery.validate.unobtrusive.min.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="/Scripts/jquery.unobtrusive-ajax.min.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="/Scripts/MicrosoftAjax.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="/Scripts/MicrosoftMvcAjax.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="/Scripts/jquery.droppy.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="/Scripts/jquery.cascadingDropDown.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="/Scripts/jquery.tablesorter.min.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script type='text/javascript'&gt; $(function () { $('#nav').droppy(); }); &lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready(function () { $("#targetStartDate").datepicker(); $("#targetEndDate").datepicker(); $("#ticketsHTMLTable").tablesorter({ sortList: [[0, 0], [1, 0]] }); $(".fakeLink").mouseover(function () { $(this).css("color", "red"); }); $(".fakeLink").mouseout(function () { $(this).css("color", "black"); }); }); &lt;/script&gt; &lt;/head&gt; </code></pre> <p>Here is my View (Razor):</p> <pre><code>@using (Ajax.BeginForm("Index", "Problem", new AjaxOptions { HttpMethod = "GET", UpdateTargetId = "ticketsTable", InsertionMode = InsertionMode.Replace })) { &lt;div class="notice"&gt; &lt;div class="prepend-1 span-2"&gt; &lt;label for="targetPriorityID"&gt; Priority&lt;/label&gt; &lt;/div&gt; &lt;div class="prepend-1 span-3"&gt; &lt;label for="targetStatusID"&gt; Status&lt;/label&gt; &lt;/div&gt; &lt;div class="span-3"&gt; &lt;label for="targetBusinessUnitID"&gt; Business Unit&lt;/label&gt; &lt;/div&gt; &lt;div class="span-3 prepend-1"&gt; &lt;label for="targetStartDate"&gt; Start Date&lt;/label&gt;&lt;/div&gt; &lt;div class="span-3 prepend-2"&gt; &lt;label for="targetEndDate"&gt; End Date&lt;/label&gt;&lt;/div&gt; &lt;div class="prepend-1 span-3 last"&gt; &amp;nbsp &lt;/div&gt; &lt;div class="prepend-1 span-2"&gt; @Html.DropDownList("targetPriorityID", new SelectList(ViewBag.Priorities as System.Collections.IEnumerable, "ID", "Title"), "All", new { @onchange = " this.form.submit();" }) &lt;/div&gt; &lt;div class="prepend-1 span-3"&gt; @Html.DropDownList("targetStatusID", new SelectList(ViewBag.Statuses as System.Collections.IEnumerable, "ID", "Title"),"All", new { @onchange="this.form.submit();" }) &lt;/div&gt; &lt;div class="span-3"&gt; @Html.DropDownList("targetBusinessUnitID", new SelectList(ViewBag.BusinessUnits as System.Collections.IEnumerable, "ID", "Title"), "All", new { @onchange = "this.form.submit();" }) &lt;/div&gt; &lt;div class="span-3 prepend-1"&gt;@Html.TextBox("targetStartDate", "", new { onchange = "this.form.submit();" })&lt;/div&gt; &lt;div class="span-3 prepend-2"&gt;@Html.TextBox("targetEndDate", "", new { onchange = "this.form.submit();" })&lt;/div&gt; &lt;div class="prepend-1 span-3 last"&gt; &lt;input type="submit" value="Hide" /&gt; &lt;/div&gt; &lt;br /&gt; &lt;br /&gt; &lt;br /&gt; &lt;/div&gt; } &lt;div id="ticketsTable"&gt; @Html.Partial("_AllTickets", Model) &lt;/div&gt; </code></pre> <p>And finally the controller,</p> <pre><code> [HttpPost] public ActionResult Index(int targetPriorityID = -1, int targetBusinessUnitID = -1, int targetStatusID = -1, string targetStartDate = "", string targetEndDate ="") { Repository&lt;Priority&gt; priorityRepository = new Repository&lt;Priority&gt;(); Repository&lt;BusinessUnit&gt; businessUnitRepository = new Repository&lt;BusinessUnit&gt;(); Repository&lt;Status&gt; statusRepository = new Repository&lt;Status&gt;(); ViewBag.Priorities = priorityRepository.GetAll(); ViewBag.BusinessUnits = businessUnitRepository.GetAll(); ViewBag.Statuses = statusRepository.GetAll(); var results = problemRepository.GetAll(); results = (targetPriorityID != -1) ? results.Where(t =&gt; t.PriorityID == targetPriorityID) : results; results = (targetBusinessUnitID != -1) ? results.Where(t =&gt; t.BusinessUnitID == targetBusinessUnitID) : results; results = (targetStatusID != -1) ? results.Where(t =&gt; t.StatusID == targetStatusID) : results; results = (targetStartDate != "") ? results.Where(t =&gt; t.DateReported &gt;= DateTime.Parse(targetStartDate)) : results; results = (targetEndDate != "") ? results.Where(t =&gt; t.DateReported &lt;= DateTime.Parse(targetEndDate)) : results; if (Request.IsAjaxRequest()) { return PartialView("__AllTickets", results); } return View(results); } </code></pre> <p>Any thoughts? </p>
 

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