错误!请求的URL未返回JSON asp.net mvc

时间:2012-07-04 11:30:22

标签: asp.net-mvc-3

我一直在使用Telerik控件,我正在使用服务器绑定,但是我必须使用Ajax绑定,这不能正常工作,我收到错误“错误!请求的URL没有返回JSON asp.net mvc” 以下是我的控制器中的代码

[GridAction]
    [Authorize(Roles = "Admin")]
    public ActionResult Edit(int id)
    {
        Contact model = _cService.getContact(id, applicationID);
        GetContactType();
        if (model != null)
            return View(model);
        else
        return View();
    }


    //
    // POST: /Contact/Edit/5
    [GridAction]
    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Edit(int id, Contact model)
    {
        try
        {
            _cService.SaveContact(model, applicationID);
            return RedirectToAction("Index");
        }
        catch
        {
            return View(model);
        }
    }

并在我的视图中使用代码

@(Html.Telerik().Grid(Model)
    .Name("Contact")
          //  .ToolBar(commands => commands.Insert())
   .DataKeys(keys => keys.Add(c => c.Id))

    .DataBinding(dataBinding => 
    {

        dataBinding.Ajax()

        .Update("Edit", "Contact", new { mode = GridEditMode.InForm, type = GridButtonType.Text })
        .Delete("Delete", "Contact", new { mode = GridEditMode.InLine, type = GridButtonType.Text });
    })

我可以做什么这个错误,这个错误出现使用警告框,我试过修改telerik.grid.min.js我已经删除了显示警告框的行,然后它没有显示我错误但也没有工作。 有人可以给我一些建议。 谢谢

1 个答案:

答案 0 :(得分:0)

这不是一个及时的回应,但正如我现在正在解决这个问题,我可以回答它。这可能是由于您的会话超时,导致IIS重定向到您的登录页面。由于它是正在返回的登录页面,而不是预期的JSON,因此您收到此消息。您可以按如下方式捕获此错误:

var checkForSessionTimeout = function (e) {
    logOnResponse = e.XMLHttpRequest.responseText.match(/.*<title.*>(Log On)<\/title>.*/);
    if (logOnResponse.length > 0 || e.XMLHttpRequest.status === 401) {
        alert("Your session has expired. You will be redirected to log on.");
        location.href = logOnUrl;
    }
}

当然,您必须定义logOnUrl以指向您的网页。

如果你自己找到答案,那么你是否应该自己找到答案,知道如何防止实际的错误提醒,因为我们提供了自己的答案?