How to pass model to partial view

I had the same issue as the OP. From one of the comments, I realized that the second parameter shouldn’t be null, i.e from

@model ParentViewModel
@Html.Partial("_Partial", Model.Child)

If Model.Child is null, then Model is passed instead of Model.Child. If there will be cases when the second parameter is null, then you will have to check first in your code and maybe pass an initialized Child as the second parameter. Something like this

@Html.Partial("_Partial", new Child())

Leave a Comment