Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Bassem Elkadeem 2 posts 72 karma points
    Jun 20, 2017 @ 10:46
    Bassem Elkadeem
    0

    Need help in making pagination with custom list

    Dears, Iam a beginner in umbraco and i want to make pagination with custom list that comes from database.
    1. First i made the following controller with an action result with template name to render view to user.

    public class formsPageController : Umbraco.Web.Mvc.RenderMvcController
    {
        public ActionResult Index(RenderModel model)
        {
            return base.Index(model);
        }
    
    
        public ActionResult ServiceProviders(ServiceProviderSearchForUmbracoViewModel model)
        {
            using (CustomUoW uow = new CustomUoW())
            {
                int categoryId = 0;
                bool parseSuccess = int.TryParse(Request["category"], out categoryId);
                if (parseSuccess)
                {
                    model.ServiceProviderSearchViewModel = new ServiceProviderSearchViewModel();
                    model.ServiceProviderSearchViewModel.ServiceCatagoryId = categoryId;
    
                    var results = uow.ServiceProviders.GetList(model.ServiceProviderSearchViewModel);
    
                    model.ServiceProviderSearchViewModel.Items = new StaticPagedList<ServiceProviderViewModel>(results, results.PageNumber, results.PageSize,
                                                                                                                results.TotalItemCount);
                    return CurrentTemplate(model);
                }
                else
                {
                    return CurrentTemplate(model);
                }             
            }
        }
    }
    

    2.Then made the following template for user:

    <div class="content my-content">
        <div class="container">
            @using (Html.BeginUmbracoForm<ServiceProviderController>("RenderCategoryServicesByCategoryId", null, new { @id = "serviceprovider_form" }))
            {
                <div class="row mb20">
                    <div>
                        <div class="row">                           
                            <div class="col-sm-4">
                                <div class="form-group">
                                    @Html.LabelFor(model => model.ServiceProviderSearchViewModel.NameEN, new { @class = "control-label" })
                                    @Html.TextBoxFor(model => model.ServiceProviderSearchViewModel.NameEN, new { @class = "form-control" })
                                    @Html.ValidationMessageFor(model => model.ServiceProviderSearchViewModel.NameEN, string.Empty, new { @class = "text-danger help-block" })
                                </div>
                            </div>
                            <div class="col-xs-12 text-left">
                                <input id="submit" value="@SharedResources.Search" class="btn btn-primary" type="submit" />
                            </div>
                        </div>
                    </div>
                </div>
            }
            <div class="clearfix text-center members">
                @if (Model.ServiceProviderSearchViewModel.Items.Any())
            {
                    <ul id="resTable">
                        @foreach (var serviceProvider in Model.ServiceProviderSearchViewModel.Items)
                        {
                            <li>
                                <a href="/ar/servicecategories/categoryproviders/providerdetails/[email protected]" class="log">
                                    <span>
                                        @serviceProvider.NameEN
                                    </span>                                    
                                </a>
                            </li>
                        }
    
                    </ul>
    
                    if (Model.ServiceProviderSearchViewModel.Items.PageCount > 1)
                    {
                        <div class="panel-footer clearfix">
                            <div class="col-xs-4 search_results_text">
                                @SharedResources.Page @Model.ServiceProviderSearchViewModel.Items.PageNumber @SharedResources.Of @Model.ServiceProviderSearchViewModel.Items.PageCount
                            </div>
    
                            @Html.PagedListPager(Model.ServiceProviderSearchViewModel.Items, page => Url.Action("RenderCategoryServicesByCategoryId", "ServiceProvider", new { PageNumber = page, Model.ServiceProviderSearchViewModel.NameAr, Model.ServiceProviderSearchViewModel.NameEN, Model.ServiceProviderSearchViewModel.ServiceCatagoryId, Model.ServiceProviderSearchViewModel.RegionId, Model.ServiceProviderSearchViewModel.CityId, Model.ServiceProviderSearchViewModel.DistrictId }), PagedListRenderOptions.ClassicPlusFirstAndLast)
                        </div>
                    }
                }
                else
                {
                    <ul id="resTable">
                        <li>
                            @SharedResources.NoResultsFound
                        </li>
                    </ul>
                }
            </div>
        </div>
    </div>
    

    3. And Make controller that extend surface controller:

    public ActionResult RenderCategoryServicesByCategoryId(ServiceProviderSearchForUmbracoViewModel searchModel)
        {
            using (CustomUoW uow = new CustomUoW())
            {
                var results = uow.ServiceProviders.GetList(searchModel.ServiceProviderSearchViewModel);
                searchModel.ServiceProviderSearchViewModel.Items = new StaticPagedList<ServiceProviderViewModel>(results, results.PageNumber, results.PageSize, results.TotalItemCount);
                return View("~/Views/" + "ServiceProviders.cshtml", searchModel);
            }
        }
    

    This line of code is not correct and give me null reference and i donot know how to handle pagination in this code and in normal mvc app this line work well. can anyone help me in this

    @Html.PagedListPager(Model.ServiceProviderSearchViewModel.Items, page => Url.Action("RenderCategoryServicesByCategoryId", "ServiceProvider", new { PageNumber = page, Model.ServiceProviderSearchViewModel.NameEN}), PagedListRenderOptions.ClassicPlusFirstAndLast)
    
Please Sign in or register to post replies

Write your reply to:

Draft