2016-09-21 47 views
0

我正在设计一个页面,我正在显示一些分页细节。除了分页,页面可以正常工作当我点击第二页时没有任何反应。所有数据cureently显示也将去。另外,当我打到第二页控制不会去我的行动方法。这是我的寻呼机代码。寻呼不在MVC4中工作

@Html.PagedListPager(Model.logDetails, page => Url.Action("Index", 
       new { page, currentFilter = ViewBag.CurrentFilter, filterdateTime=ViewBag.filterdateTimepageSize, })) 
       Page @(Model.logDetails.PageCount < Model.logDetails.PageNumber ? 0 : Model.logDetails.PageNumber) of @Model.logDetails.PageCount 

这是我的操作方法代码。

[HttpPost] 
     public ActionResult Index(int? clientId, DateTime? dateofAction,string typeofDocument,string employeeID,string citizenId,int? currentFilter,DateTime? filterdateTime,int? page) 
     { 
      DB_KYC3Entities db = new DB_KYC3Entities(); 
      ViewBag.docTypes = new SelectList(db.tm_doc_type, "doc_typeid", "doctype_name"); 
      if (clientId != null) 
      { 
       page = 1; 
      } 
      else 
      { 
       clientId = currentFilter; 
      } 
      if(dateofAction!=null) 
      { 
       page = 1; 
      } 
      else 
      { 
       dateofAction = filterdateTime; 
      } 
      ViewBag.CurrentFilter = clientId; 
      ViewBag.filterdateTime = dateofAction; 
      int pageSize = 8; 
      int pageNumber = (page ?? 1); 
      VerificationLogBAL obj = new VerificationLogBAL(); 
      int docType = obj.GetDocDetails(typeofDocument); 
      List<logDetails> logDetails = obj.getlogDetails(clientId?? default(int), dateofAction?? DateTime.Now, docType, employeeID, citizenId); 
      IPagedList<logDetails> pagedLog = logDetails.ToPagedList(pageNumber, pageSize); 
      logDetailsEnumeration model = new logDetailsEnumeration(); 
      ViewBag.checkData = logDetails.Count; 
      model = new logDetailsEnumeration() 
      { 
       logDetails= pagedLog 
      }; 
      return View("Index",model); 
     } 

这是我的查看代码。

<div class="forms"> 
    @using (Html.BeginForm("Index", "VerificationLog", FormMethod.Post)) 
    { 
     @Html.AntiForgeryToken() 
     @Html.ValidationSummary(true) 
     <div class="message"></div> 

     <div class="loginUsernamePassword"> 
      <i class="fa fa-user"></i> 
      <table width="100%" border="0" cellspacing="0" cellpadding="0" class="dataTable tableHover"> 
       <tr> 
        <th width="8%" scope="col">Client ID</th> 
        <th width="20%" scope="col"> 
         <div class="form-box form-box-default"> 
          @Html.TextBox("clientId", ViewBag.CurrentFilter as string, new { @id = "clientId", @placeholder = "Client ID", @class = "form-control", @maxlength = 20 }) 

         </div> 
        </th> 
        <th width="10%" scope="col">Date Of Action</th> 
        <th width="20%" scope="col"> 
         <div class="form-box form-box-default"> 
          @Html.TextBox("dateofAction", ViewBag.filterdateTime as string, new { @id = "dateofAction", @placeholder = "Date Of Action", @class = "txtBox form-control calender validate[required]" }) 
         </div> 
        </th> 
        <th width="15%" scope="col">Type Of Document</th> 
        <th width="17%" scope="col"> 
         <div class="form-box form-box-default"> 
          @*@Html.TextBox("typeofDocument", ViewBag.filterdateTime as string, new { @id = "typeofDocument", @placeholder = "Type Of Document", @class = "form-control", @maxlength = 20 })*@ 
          @Html.DropDownList("docTypes",null,new {@id = "typeofDocument", @placeholder = "Type Of Document", @class = "form-control"}) 
               </div> 
        </th> 
       </tr> 
       <tr> 
        <th width="15%" scope="col">Employee ID</th> 
        <th width="17%" scope="col"> 
         <div class="form-box form-box-default"> 
          @Html.TextBox("employeeID", ViewBag.filterdateTime as string, new { @id = "employeeID", @placeholder = "Employee ID", @class = "form-control", @maxlength = 20 }) 

         </div> 
        </th> 
        <th width="15%" scope="col">Citizen ID</th> 
        <th width="17%" scope="col"> 
         <div class="form-box form-box-default"> 
          @Html.TextBox("citizenId", ViewBag.filterdateTime as string, new { @id = "citizenId", @placeholder = "Citizen ID", @class = "form-control", @maxlength = 20 }) 


         </div> 
        </th> 
        <th width="10%" scope="col" colspan="2"> 
         <input type="submit" value="Search" class="btn btn-primary btn-cons search" /> 
       </tr> 
      </table> 

      </div> 
      } 

     </div> 
    @if (Model != null && Model.logDetails.Count != 0) 
     { 
      <br /> 
      <h2>Verification Log</h2> 
      <br /> 
      <div id="GridDetails"> 
       <table width="100%" border="0" cellspacing="0" cellpadding="0" class="dataTable tableHover"> 
        <tr> 
         <th>Label</th> 
         <th>Value</th> 
         <th>UpdatedOn</th> 
         <th>UpdatedBy</th> 
         <th>UpdatedStatus</th> 
         <th>RejectComment</th> 
        </tr> 
        @foreach (var group in Model.logDetails) 
        { 
         <tr> 
          <td>@group.contentLabel</td> 
          <td>@group.contentValue</td> 
          <td>@group.updatedOn</td> 
          <td>@group.updatedBy</td> 
          <td>@group.updatedStatus</td> 
          <td>@group.rejectComment</td> 
         </tr> 

        } 
       </table> 


    [HttpGet] 
public ActionResult Index() 
{ 
    DB_KYC3Entities db = new DB_KYC3Entities(); 
    ViewBag.docTypes = new SelectList(db.tm_doc_type, "doc_typeid", "doctype_name"); 
    return View(); 
} 

当我点击第二页控制将不会去我的索引方法也。另外我有5个文本框,所以我需要保留viewbag中的全部5个文本框值?有人能告诉我吗?在此先感谢

回答

0

PagedListPager进行GET调用,而不是POST,因此您需要从Index()方法中删除[HttpPost]属性。与之相关,你需要改变的形式也使GET

@using (Html.BeginForm("Index", "VerificationLog", FormMethod.Get)) 

是的,你需要在viewbag(或使用视图模型更好)保留所有5个文本框的值,并添加这些在寻呼机Url.Action()中的值与您正在添加的方式相同currentFilterfilterdateTime

+0

此功能与魅力类似。但我有一个疑问。我也有下面的方法。因为在页面加载我绑定下拉与数据库值。它会冲突吗? [httpget] public ActionResult Index(){} –

+0

您只能拥有一个具有相同签名的GET方法。你不需要你的其他索引方法,它应该被删除。但是你需要在任何地方停止使用'ViewBag',并使用一个视图模型,这样你就可以很好地绑定它。该模型将包括属性(比如说)int SelectedDocument'和IEnumerable DocumentList'(以及'Client','DateofAction'的属性等 –

+0

谢谢我会尝试使用模型。我可以有一些有用的链接在哪里我可以使用更多的模型比viewbags在寻呼概念? –