Click here to Skip to main content
15,904,497 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

i have a mvc application where i return two list from the controller to the view. one list is of Clients and other list is products. i want paging in product list anb client list will be bind to check box for filter functionality. now when i apply paging using paged list .mvc it do not apply paging because of the two lists are bind in the view. here is my code .

MODEL :
C#
public class Clients
  {
      public int clientID;
      public string name;
      public string email;
      public string phoneNumber;
  }

  public class Projects
  {
      public int ProjectID;
      public string Title;
      public int SourceLanguage;
      public int RootFolder;
      public int WordCount;
      public int client;
      public string trackStatus;
      public string invoice;
      public string trackPath;
      public string ClientName;
  }

  public class ProjectClientList
  {
      public List<Clients> ClientList { get; set; }
      public List<Projects> ProjectList { get; set; }

  }




Controller :

C#
[HttpGet]
      public ActionResult ListProduct(int Page = 1 , int PageSize = 2)
      {
          Clients objClient = new Clients();
          List<Clients> ClientList = new List<Clients>();
          ClientList = DataAccess.GetAllClients();
          List<Projects> ProjectList = new List<Projects>();
          ProjectList = DataAccess.GetAllProjects();

          ProjectClientList objList = new ProjectClientList();
          objList.ProjectList = ProjectList;
          objList.ClientList = ClientList;

          List<ProjectClientList> viewModelList = new List<ProjectClientList>();
          viewModelList.Add(objList);

          PagedList.PagedList<ProjectClientList> pagedData = new PagedList.PagedList<ProjectClientList>(viewModelList, Page, PageSize);
          return View(pagedData.ToPagedList(Page,PageSize));
      }



view :

C#
@model PagedList.IPagedList<Strom.Models.ProjectClientList>
@using PagedList.Mvc;

   <div class="col-md-2" style="border: 1px solid #dadada; padding: 0px;">
                    <h3 class="top-heading">Filters </h3>
                    <p style="color: 3c6a21rgb(60, 106, 33); padding: 7px; margin: 0px ! important; font-size: 18px;">Company:</p>
                    <div class="list-group">
                        @foreach (var item in Model)
                        {
                            if (@item.ClientList != null && @item.ClientList.Count > 0)
                            {
                                for (int k = 0; k < @item.ClientList.Count; k++)
                                {
                                    <a href="#" class="list-group-item"> <input type="checkbox" > @item.ClientList[k].name </a>
                                }
                            }
                        }

                    </div>

                </div>

  <div id="DivList" class="row">

                        @foreach (var item in Model)
                        {
                            if (@item.ProjectList != null && @item.ProjectList.Count > 0)
                            {
                                for (int k = 0; k < @item.ProjectList.Count; k++)
                                {
                                    <div class="col-sm-4 col-lg-4 col-md-4">
                                        <div class="thumbnail">
                                            <input type="hidden" id="hdClientID" value="@item.ProjectList[k].client" />
                                            <h3 class="top-heading">@item.ProjectList[k].ClientName </h3>
                                            <div class="caption">
                                                <h4 class="pull-right">
                                                    Quot: 595.68<br />
                                                    Cos: 433.90
                                                </h4>
                                                <h4>
                                                    <a href="#">@item.ProjectList[k].Title</a>
                                                </h4>

                                            </div>
                                            <div class="ratings">
                                                <p class="pull-right">Due 11/01/14<br>PM : Alison Fischer</p>
                                                <p>
                                                    <span>Documents (0/1) </span><br>
                                                    <span>Documents (0/1) </span>
                                                </p>
                                            </div>
                                        </div>
                                    </div>
                                }
                            }
                        }

                    </div>

@Html.PagedListPager(Model,
           page => Url.Action("ListProduct", new { page }))
Posted

1 solution

Create a viewModel class and Merge all the client and Project properties in to one and then join the ProjectList and ClientList using linq and select in to viewmodel

C#
public class ProjectClientViewModel{
 public int clientID;
        public string name;
        public string email;
        public string phoneNumber;
        public int ProjectID;
        public string Title;
        public int SourceLanguage;
        public int RootFolder;
        public int WordCount;
        public int client;
        public string trackStatus;
        public string invoice;
        public string trackPath;
        public string ClientName;
}


C#
var finaResult=join query.Select(model=>new ProjectClientViewModel{})

finally bind the finalResult to PagedList
Hope this helps
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900