0

Pour le site sur lequel mes collègues et moi travaillons, nous avons utilisé le format dataTable de www.dataTables.net et nous devons utiliser le traitement côté serveur à cause de combien les tables grandissent. Voici la vue:dataTable.net Traitement côté serveur: ne semble pas se rafraîchir

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %> 
<script type="text/javascript" charset="utf-8"> 
    $(document).ready(function() { 
    $('#adminUnassignedTable').dataTable({ 
     "bProcessing": true, 
     "bServerSide": true, 
     "sAjaxSource": "/Admin/UpdateUnassignedReviewer", 
     "sPaginationType": "full_numbers" 
    }); 
    }); 
</script> 

<h2>Unassigned IPBs</h2> 
<% 
    using (Html.BeginForm("Assign","Admin",FormMethod.Post)) 
    { 
    Html.RenderPartial("AssignmentControls", "Reviewer"); 
%> 
<table cellpadding="0" cellspacing="0" border="0" class="display" id="adminUnassignedTable"> 
<thead><tr> 
<th>IPB Number</th> 
<th>IPB Pub Date</th> 
<th>Change Number</th> 
<th>Change Date</th> 
<th>Total # of Parts</th> 
<th>Total # of Report Parts</th> 
<th>ALC</th> 
<th>Date Loaded</th> 
<th>Priority</th> 
<th>Update</th> 
</tr></thread> 
<tbody><tr><td colspan="12" class="dataTable_empty">Loading Data From Server</td></tr></tbody> 
</table> 
<% 
    } 
%> 

Voici la fonction sAjaxSource dans les AdminController.cs:

public void UpdateUnassignedReviewer() 
{ 
    int[] nArrayStatus = { (int)PTA.Helpers.Constants.State.Queue } 
    int nTotalRecordCount = 0; 
    string strEcho = ""; 
    _DisplayRecords = PTA.Helpers.Utility.BeginServerSideProcessing(HttpContext.Request.QueryString, nArrayStates, (int)PTA.Helpers.Constants.Location.Reviewer, ref nTotalRecordCount, ref strEcho); 
    string strOutput = ""; 
    if (_DisplayRecords.Count() <= 0) 
    { 
    PTA.Helpers.Utility.WriteBlankRecord(ref strOutput, strEcho, 12); 
    } 
    else 
    { 
    strOutput += "{\"sEcho\":" + strEcho + ", "; 
    strOutput += "\"iTotalRecords\": " + nTotalRecordCount.ToString() + ", "; 
    strOutput += "\"iTotalDisplayRecords\": " + nTotalRecordCount.ToString() + ", "; 
    strOutput += "\"aaData\": ["; 
    int nCounter = 0; 
    foreach (IPB ipb in _DisplayRecords) 
    { 
     strOutput += "[ " 
     strOutput += "\""; 
     strOutput += PTA.Helpers.Utility.CreateDetailsLinkHTML(ipb.ID.ToString(), ipb.IPBName) + "\","; 
     strOutput += "\"" + ipb.PubDate + "\","; 
     strOutput += "\"" + ipb.Change + "\","; 
     strOutput += "\"" + ipb.ChangeDate + "\","; 
     strOutput += "\"" + ipb.TotalParts + "\","; 
     strOutput += "\"" + ipb.TotalPartsReport + "\","; 
     strOutput += "\"" + ipb.ALC + "\","; 
     strOutput += "\"" + ipb.DateAdded + "\","; 
     strOutput += "\"" + ipb.Priority + "\","; 
     strOutput += "\"" + PTA.Helpers.Utility.CreateCheckBoxHTML(ipb.ID.ToString(), nCounter++); 
     strOutput += "\""; 
     strOutput += "]"; 

     if(ipb != _DisplayRecords.Last()) 
     { 
     strOutput += ", "; 
     } 
    } 
    } 

    strOutput += "]}"; 
    Response.Write(strOutput); 
} 

est ici la fonction Assigner

[AcceptVerbs(HttpVerbs.Post)] 
public ActionResult Assign(string PriorityDropDown, string UserDropDown, string ActionDropDown) 
{ 
    ResetTempData(ref statusID, ref locationID, ref area); 

    int ipb_id = 0, 
     action = -1; 

    action = Request.Form["ActionDropDown"].ToString() == null || Request.Form["ActionDropDown"].ToString() == "" ? -1 : Convert.ToInt32(Request.Form["ActionDropDown"]); 

    string strUser = "", 
     strPriority = ""; 

    strUser = Request.Form["UserDropDown"]; 
    strPriority = Request.Form["PriorityDropDown"]; 

    string[] strTemp = Request.Form.AllKeys; 
    foreach(string str in strTemp) 
    { 
    if(str.Contains("AssignCheck")) 
    { 
     ipb_id = Convert.ToInt32(Request.Form[str]); 

     if(action > -1 || (strUser != null || strUser != "") || (strPriority != null || strPriority != "")) 
     { 
     switch (action) 
     { 
      case -1: 
      Update(ipb_id, strPriority, strUser); 
      break; 
      case 1: 
      case 2: 
      case 5: 
      case 8: 
      Action(ipb_id, action); 
      break; 
      default: break; 
     } 
     } 
    } 
    } 

    return RedirectToAction("AdminView"); 
} 

Voici la fonction AdminView

public ActionResult(int? statusID, int? locationID) 
{ 
    if (!System.Web.HttpContext.Current.User.IsInRole("Admin")) 
    { 
    return RedirectToAction("Index", "Home"); 
    } 

    PTA.Modesl.DataFactory factory = new DataFactory(); 
    if(statusID == null) 
    { 
    statusID = (int)PTA.Helpers.Constants.State.Queue; 
    ViewData["status"] = statusID; 
    } 

    if(locationID == null) 
    { 
    locationID = (int)PTA.Helpers.Constants.Location.Reviewer; 
    ViewData["location"] = locationID; 
    } 

    TempData["pageStatus"] = statusID; 
    TempData["pageLocation"] = locationID; 
    TempData["Area"] = Request.QueryString["Area"]?? "Unassigned"; 

    return View(); 
} 

En outre, en tant que note, ma machine dev n'est pas la même que ma machine réseau. Donc, je ne peux pas copier et coller, je ne peux pas non plus utiliser des clés USB. Par conséquent, je dois taper manuellement tout. Donc, si vous voyez des fautes de frappe, demandez-moi et je vous ferai savoir si c'est correct. En outre, il y a deux actions que vous pouvez demander de voir, je ne les ai pas simplement saisies juste à cause du temps qu'il a fallu pour taper tout le reste. Action et assignation. Si vous voulez/devez les voir, faites le moi savoir. Merci.

+0

StringBuilder pourrait être votre ami pour une partie de ce codebebe code ,, – RobS

+0

lol. Je sais que ce n'est pas joli. Mes collègues et moi touchons tout à différents moments. Je suis un stickler de format et un "one-liner" chaque fois que je peux. Juste tant que la ligne n'est pas 500 caractères. J'abuse de l'enfer des déclarations ternaires. Ils m'ont expliqué comme ils aiment avoir autant de points de rupture que possible. Bah. – XstreamINsanity

Répondre

0

lol. La réponse est d'utiliser la dernière version. J'utilisais 1.6.7 alors que j'aurais dû utiliser 1.7.0. Cela fonctionne maintenant bien.

Questions connexes