Razor Pages - Can't pass different model to partial view within a page handler

This appears to be bug in newly introduced Partial() in ASP.NET Core 2.2 where model parameter seems to be completely redundant, because "this" is the only thing it will accept.

If you however use PartialViewResult() it will work. Should be simpler and more readable than the accepted solution.

Just swap this

return Partial("_CreateMeetingPartial", new ManipulationDto());

with this

return new PartialViewResult
{
    ViewName = "_CreateMeetingPartial",
    ViewData = new ViewDataDictionary<ManipulationDto>(ViewData, new ManipulationDto())
};

To resolve above issue, I had to do below. Note that I do not have [BindProperty] attribute on my ManipulationDto property because I have multiple models on my page. If you have multiple models and you have validation (e.g. required properties), all of them will trigger in razor pages which is different from MVC. The way to handle it in my case was to pass the model directly as a parameter but also making sure to have a public property which I can assign all the values in case model state validation fails.

If you do not have multiple unique models, each with their own validation, you can just apply the bindproperty attribute and not worry.

public class BoardMeetingsModel : PageModel
{ 
      //this gets initialized to a new empty object in the constructor (i.e. MeetingToManipulate = new ManipulationDto();)
      public ManipulationDto MeetingToManipulate { get; set; }

      //ctor
      //properties

      public IActionResult OnGetFetchCreateMeetingPartial(ManipulationDto meetingToManipulate)
          {
             //send the page model as the object as razor pages expects 
             //the page model as the object value for partial result
             return Partial("_CreateMeetingPartial", this);
          }

      public async Task<IActionResult> OnPostCreateMeetingAsync(CancellationToken cancellationToken, ManipulationDto MeetingToCreate)
        {
            if (!ModelState.IsValid)
            {
                //set the pagemodel property to be the values submitted by the user
                //not doing this will cause all model state errors to be lost
                this.MeetingToManipulate = MeetingToCreate;
                return Partial("_CreateMeetingPartial", this);
            }
            //else continue
         }
}