2016-09-21 3 views
0

ページングを使用して詳細を表示するページを1つ設計しています。ページはページングを除いて正常に動作します。 2番目のページをクリックすると何も起こりません。表示されたすべてのデータも表示されます。また、私は2番目のページのコントロールにヒット私のアクションメソッドに移動しないでください。これは私のページャのコードです。MVC4でページングが動作しない

これは私のアクションメソッドコードです。

[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(); 
} 

私が2番目のページのコントロールをクリックしても、私のインデックスメソッドに行くことはありません。また、私は5つのテキストボックスを持っているので、私はビューバックのすべての5つのテキストボックスの値を保持する必要がありますか?誰かが教えてくれますか?前もってありがとう

答えて

0

PagedListPagerは、[HttpPost]属性をIndex()メソッドから削除する必要があるため、POSTではなくGET呼び出しを行います。それに関連付けられている、あなたも(ビューモデルを使用して、またはそれ以上)viewbag内のすべての5のテキストボックスの値を保持GET

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

を作るはい、あなたはに必要にフォームを変更し、それらを追加する必要がありますページャの値はUrl.Action()と同じ方法で追加しますcurrentFilterfilterdateTime

+0

これは魅力的です。しかし、私は1つの疑いがあります。私は以下の方法も持っています。ページの負荷では、私はデータベースの値をバインディングドロップダウンです。だからそれは矛盾しますか? [httpget] public ActionResult Index(){} –

+0

同じシグネチャで1つのGETメソッドしか持つことはできません。他のインデックスメソッドは必要ありません。削除する必要があります。しかし、あなたはどこでも 'ViewBag'のこのひどい使い方をすべて止め、ビューモデルを使って強くバインドする必要があります。そのモデルには 'int SelectedDocument'と' IEnumerable DocumentList'( 'Client'、' DateofAction'などのプロパティ)のプロパティが含まれています –

+0

私はモデルを使用しようとします。どこで私はページングコンセプトのビューバックよりも多くのモデルを使用できますか? –

関連する問題