Copied to clipboard

Flag this post as spam?

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


  • Tom Engan 430 posts 1173 karma points
    Oct 06, 2017 @ 08:57
    Tom Engan
    0

    Url.Action: From view to partial view (X.PagedList.Mvc)

    @Html.PagedListPager((IPagedList)ViewBag.pageList, page => Url.Action("TopMostDiffHikingDestinationsGroupedByQuantity", new { page }) )
    

    Url.Action opens a partial view in a new window, but of course I want to load the partial view TopMostDiffHikingDestinationsGroupedByQuantity into my current site, so how can I rewrite this line?

    Note, I'm going to have several different PagedList's on the same page/view.

  • Tom Engan 430 posts 1173 karma points
    Oct 09, 2017 @ 11:07
    Tom Engan
    0

    Anyone who has good control of which different codes to use for view and partial view, like here?

    And my surfacecontroller returns partial view, so it works when loading the page, but not with paging..

    [HttpGet]
    public ActionResult TopMostDiffHikingDestinationsGroupedByQuantity(int? page)
    {
        // Some more codes..
    
        ViewBag.pageList = topMostDiffHikingDestinationsGroupedByQuantity.ToPagedList(pageIndex, pageSize);
        return PartialView("TopMostDiffHikingDestinationsGroupedByQuantity", model);
    }
    

    And I load the partial view via this macro, named TopMostDiffHikingDestinationsGroupedByQuantity:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    @*actionName: TopMostDiffHikingDestinationsGroupedByQuantity - controllerName: HikingDestinationSurface*@
    @Html.Action("TopMostDiffHikingDestinationsGroupedByQuantity", "HikingDestinationSurface", new { page = 1 })
    

    And this is the partial view:

    @inherits UmbracoViewPage<Neoweb.Models.HikingDestinationViewModel>
    @using X.PagedList.Mvc
    @using X.PagedList;
    
    <div class="panel panel-primary">
        <h4>Flest ulike turmål, år @DateTime.Now.Year:</h4>
        <table class="table-hover">
            <tr>
                <th>Navn</th>
                <th>Antall</th>
            </tr>
            @foreach (var visit in Model.Visits)
            {
                <tr>
                    <td>@visit.HikerName</td>
                    <td>@visit.NumberOfVisits</td>
                </tr>
            }
            @if (Model.Visits.Count == 0)
            {
                <tr>
                    <td colspan="2">Ingen godkjente turmål</td>
                </tr>
            }
            <tr>
                <td colspan="2">
                    @Html.PagedListPager((IPagedList)ViewBag.pageList, page => Url.Action("TopMostDiffHikingDestinationsGroupedByQuantity", new { page }), PagedListRenderOptions.OnlyShowFivePagesAtATime)
                </td>
            </tr>
        </table>
    </div>
    
  • Tom Engan 430 posts 1173 karma points
    Oct 09, 2017 @ 14:21
    Tom Engan
    100

    So I had to add a jQuery function. Is this the only way, or is there another or safer alternative with html helpers, or other solutions?

    @inherits UmbracoViewPage<Neoweb.Models.HikingDestinationViewModel>
    @using X.PagedList.Mvc
    @using X.PagedList
    
    <script>
        $(function () {
            $('#replaceMyTr').on('click', 'a', function () {
                $.ajax({
                    url: this.href,
                    type: 'GET',
                    cache: false,
                    success: function (result) {
                        $('#replaceMyDiv').html(result);
                    }
                });
                return false;
            });
        });
    </script>
    
    <div id="replaceMyDiv">
      <div class="panel panel-primary">
        <h4>Flest ulike turmål, år @DateTime.Now.Year:</h4>
        <table class="table-hover">
            <tr>
                <th>Navn</th>
                <th>Antall</th>
            </tr>
            @foreach (var visit in Model.Visits)
            {
                <tr>
                    <td>@visit.HikerName</td>
                    <td>@visit.NumberOfVisits</td>
                </tr>
            }
            @if (Model.Visits.Count == 0)
            {
                <tr>
                    <td colspan="2">Ingen godkjente turmål</td>
                </tr>
            }
            <tr id="replaceMyTr">
                <td colspan="2">
                        @Html.PagedListPager((IPagedList)ViewBag.pageList,
                       page => Url.Action("TopMostDiffHikingDestinationsGroupedByQuantity",
                       new { page, PagedListRenderOptions.OnlyShowFivePagesAtATime }),
                       new PagedListRenderOptions { Display = PagedListDisplayMode.IfNeeded })
                </td>
            </tr>
        </table>
      </div>
    </div>
    
Please Sign in or register to post replies

Write your reply to:

Draft