當在我的會話變量我的ajax調用正常工作的值...但是,當一個會話已逾時它似乎不工作返回空的JSON結果....爲什麼在asp.net mvc中會話超時後,jquery ajax調用失敗?
public JsonResult GetClients(int currentPage, int pageSize)
{
if (Session["userId"]!=null)
{
var clients = clirep.FindAllClients(Convert.ToInt32(Session["userId"])).AsQueryable();
var count = clients.Count();
var results = new PagedList<ClientBO>(clients, currentPage - 1, pageSize);
var genericResult = new { Count = count, Results = results ,isRedirect=false};
return Json(genericResult);
}
else
{
var genericResult = new {redirectUrl = Url.Action("Create", "Registration"), isRedirect = true };
return Json(genericResult);
}
}
但是其他部分一點兒也不似乎工作....
success: function(data) {
alert(data.Results);
if (data.isRedirect) {
window.location.href = data.redirectUrl;
}
}
編輯:
我的Global.asax有這個,
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Clients",
"Clients/{action}/{id}",
new { controller = "Clients", action = "Index", id = "" }
);
routes.MapRoute(
"Registrations",
"{controller}/{action}/{id}",
new { controller = "Registration", action = "Create", id = "" }
);
}
當會話超時時它實際上在做什麼?它是否返回一個JSON對象? – 2010-06-08 07:20:06
@matthew雅它返回一個JSON對象,但它不會被重定向到我的登錄視圖,而是它保持在同一視圖中... – 2010-06-08 07:45:52
使用Firebug在Firefox中打開您的頁面,並在警報上放置一個斷點(數據。結果)行,您應該能夠檢查該對象。通常使用javascript,如果發生錯誤,當前腳本塊的執行將終止。您需要知道您嘗試訪問的屬性是否在對象中可用。 此外,請嘗試只是「location.href」,看看是否有所作爲。 – 2010-06-08 07:48:28