0

I've read a bunch of posts here on SO re: this and still don't get it.

I have a view with a partial view paging control in it that needs access to the same model as the parent view.

Parent View:

model IEnumerable<Models.ExchangeBrowseViewModel>
@{
    ViewBag.Title = metaExchange.Index_PageTitle;
}
@section styles
{        
    <link rel="stylesheet" type="text/css" href="/incl/css/bp-default.css" />
    <link rel="stylesheet" type="text/css" href="/incl/css/bp-component.css" /> 
    <link rel="stylesheet" type="text/css" href="/incl/css/paging.css" />   
}
<hgroup>
    <h2>@metaExchange.Index_InlineTitle</h2>
    <h3>@ViewBag.Message</h3>
</hgroup>

<div class="container">
    <div class="row">
        <div class="col-md-2" style="border: 1px solid #000000">
             @Html.Partial("_ItemsSearch_BasicPartial");         
        </div>
        <div class="col-md-10">
            @Html.Action("Pagination", new {showWell=false, model=Model});

Pagination Action:

[AllowAnonymous]
    [ChildActionOnly]
    public ActionResult Pagination(ExchangeBrowseViewModel model, bool showWell)
    {
        ViewBag.ShowWell = showWell;
        return PartialView("_ItemsList_Pagination", model);
    }

Pagination Partial View

@model IPagedList<Models.ExchangeBrowseViewModel>
<div class="mvcpagination">
    @Html.Raw(Ajax.Pager(
        new Options
            {
                PageSize = Model.PageSize,
                TotalItemCount = Model.TotalItemCount,
                CurrentPage = Model.PageNumber,
                ItemTexts = new ItemTexts() {Next = ">>", Previous = "<<", Page = ""},
                ItemIcon = new ItemIcon() {First = "icon-backward", Previous = "icon-chevron-left", Next = "icon-chevron-right", Last = "icon-forward"},
                TooltipTitles = new TooltipTitles() {Next = "Next", Previous = "Previous", Page = "Page {0}."},
                Size = Size.normal,
                Alignment = Alignment.right,
                IsShowControls = true,
                IsShowFirstLast = true,
                CssClass = "light-theme"
            },
        new AjaxOptions
            {
                UpdateTargetId = "grid-list",
                OnBegin = "beginPaging",
                OnSuccess = "successPaging",
                OnFailure = "failurePaging"
            }, new {controller = "Requests", action = "Index", requestTitle = ViewData["requestTitle"]}))
    @if (ViewBag.ShowWell)
    {
        <div class="well">
            Showing <span class="badge badge-success">@Model.ItemStart</span> to <span class="badge badge-success">@Model.ItemEnd</span>
            of <span class="badge badge-info">@Model.TotalItemCount</span> entries</div>
    }
</div>

The problem is the model is always null inside the action method and therefore the partial throw a NullReference exception trying to access model properties.

1 Answer 1

1

You pass ExchangeBrowseViewModel in your Pagination action and binds it to wrong type in controller method.

You pass the whole IEnumerable<Models.ExchangeBrowseViewModel> model from parent view to action and want to get ExchangeBrowseViewModel. But model binder can't find appropriate data, that's why it's null.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.