2

Is there a way to re-render a partial from a PageModel?

@foreach (var group in Model.Groups)
{
    <partial name="_OverviewAction" model="@group" />
}

The following function should replace the partial with a new one.

But this won't work because the Partial() only accepts a model from the same type as the PageModel.

public IActionResult OnPostDeleteGroup(string id)
{
    var group = GroupService.GetGroup(id);

    /*... some code ...*/

    return Partial("_OverviewAction", group);
}
1
  • Do you mean re-useable or portable? Commented Mar 7, 2019 at 7:24

1 Answer 1

2

When the Partial helper method was introduced in 2.2, I believe that the intention was to allow you to pass in any model, but the actual implementation seems buggy (or to behave differently to expectations). So you can fall back on the way to call partials that works in 2.1:

return new PartialViewResult {
        ViewName = "_OverviewAction",
        ViewData = new ViewDataDictionary<data type for the group variable goes here>(ViewData, group)
    }; 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.