2013-03-14 38 views
0

我正在使用mvc格式的JQuery數據表。使用條件綁定JQuery數據表。但是我不知道如何去解決這個問題,顯示錯誤信息。我需要顯示錯誤警報消息服務器端是客戶端。我的示例代碼:如何在JQuery數據表中發送錯誤消息警報

public ActionResult Action(string EmpNo) 
     { 
      if (condition) 
      { 
       // data table passing 
      } 
      else 
      { 
       //here how to show the error message client side or server side 
      } 
     } 

回答

0

您可以返回JavascriptResult。 JavaScriptResult

return Javascript("yourJS COde"); 

一些這樣的事

public ActionResult TestJavaScript() { 
    string s = "$('#divResultText').html('JavaScript Passed');"; 
    return JavaScript(s); 
} 
+0

但我使用的數據表,這樣不可用的 – user279stack 2013-03-14 05:05:35

+0

我們在客戶端使用jauery數據表我們只需要發送數據表格中的錯誤 – user279stack 2013-03-14 05:16:56

0

你應該任意對象返回JsonResult(或實物,如果你已經創建了一個)匹配的數據表的預期收益簽名。喜歡的東西:

var result = // do something, get a list of stuff etc 

return new JsonResult { 
    // `Data` is the thing that turns into your json response 
    Data = new { 
     error = result.Success ? "" : result.Message, 
     fieldErrors = new bool[0], // just to fake an empty array 
     data = new bool[0], 
     aaData = result.Success ? result.Items.Select(o => new { 
      //use arbitrary column names if you've specified them in config with `aoColumns` and `mDataProp`, see comment below 
      OrderID = o.ID, 
      ChannelID = o.Partner, 
      ReferenceKey = o.PartnerReferenceKey, 
      o.CustomerEmail, 
      Status = o.Status.ToString(), 
      Value = o.Total, 
      CreatedOn = o.CreatedOn.ToString("yyyy-MM-dd HH:mm:ss"), // provide in interpretable format 
     }) : (object) new bool[0], // must return an empty list in order for it to understand errors 
     iTotalRecords = result.TotalCount, 
     iTotalDisplayRecords = result.TotalCount, // should be different if filtering 
     sEcho // this is provided by the request, not sure what it means... 
    } 
}; 

對於從Ajax響應自定義列名,你要檢討: