2012-07-04 46 views
1

我一直在使用Telerik控件,我使用的是服務器綁定,但我必須使用Ajax綁定,這是不正常工作,我得到錯誤「錯誤!請求的URL沒有返回JSON asp.net的MVC」 以下是代碼在我的控制器錯誤!請求的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我已經刪除了顯示一個警告框的行,然後它不顯示我的錯誤,但也不起作用。 有人可以給我一些建議。 謝謝

回答

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指向你的頁面。

如果有問題,如果您自己找到答案,想知道如何防止實際的錯誤警報,因爲我們提供自己的?

相關問題