當用戶超時或者會話cookie被刪除時使用MVC 5認證,用戶被重定向到登錄頁面。MVC認證超時/會話cookie被刪除後的Ajax請求
這適用於整頁加載,但對於我的Ajax調用,這打破了客戶端。重定向在身份驗證頁面顯示時運行,但沒有響應(在標準加載輪後)。
我很確定這是某種JS問題。
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();
}
});
});
});
主視圖:
@{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>
局部視圖:
@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>
控制器:
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);
}
我得到的錯誤客戶端:
如果任何人有他們會是非常讚賞的任何想法!
你也可以顯示服務器端(控制器)代碼嗎? –
嗨,我已經添加了控制器。謝謝。 – MattMcGowan
試試這個JS內部的剃鬚刀代碼:http://stackoverflow.com/questions/5614941/mix-razor-and-javascript-code – rico