当在我的会话变量我的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