Using MVC 5 authentication when a user times out, or the session cookie cookie is deleted, the user gets redirected to the login page.
This works fine on full page loads, however for my Ajax calls this breaks client side. The redirect works as the authentication page shows up, but is unresponsive (behind the standard loading wheel).
I'm pretty sure this is some sort of JS issue.
JS:
$(function () {
$('#dealSearchForm').on("submit", function (e) {
e.preventDefault();
$.ajax({
url: this.action,
type: this.method,
data: $(this).serialize(),
success: function (data) {
$('#dealSearchForm').html(data);
},
complete: function (data) {
$('#searchResults').show();
}
});
});
});
Main View:
@{Html.RenderPartial("_DealSearch");}
<script src="@Url.Content("~/Scripts/DealSearch.js")"></script>
<script>
$(document).ready(function () {
@if (Model.Deals.Count > 0) {
@Html.Raw("$('#searchResults').show();");
}
});
</script>
Partial View:
@using (Html.BeginForm("DealSearch", DealManagement, FormMethod.Post, new { @id = "dealSearchForm" }))
{
/* Search filters etc */
<div class="col-xs-7">
<button id="button-search" class="btn btn-primary pull-right" type="submit" data-loading-text="Please wait...">Search</button>
</div>
<div id="searchResults">
/* Grid with results */
</div>
Controller:
public virtual ActionResult Index()
{
var model = new DealSearchModel();
return this.View(model);
}
public virtual ActionResult DealSearch(DealSearchModel model)
{
// Get deals from service, uses search criteria
model.Deals = GetDeals(model);
// Return the view
return PartialView(MVC.DealManagement.Views._DealSearch, model);
}
I get errors client side:
If anyone has any ideas they'd be very much appreciated!