Access Parent Model from partial view

前端 未结 5 2050
半阙折子戏
半阙折子戏 2021-01-07 22:00

I\'m asking because the partial view I will create is blank, with the purpose of creating a new child entity. I just need a quick, regardless if dirty, way to access the Pa

5条回答
  •  天命终不由人
    2021-01-07 22:53

    This ended up working for me.

    @model MyViewModel
    ...
    @Html.Partial("_myPartial", new ViewDataDictionary { { "id", Model.Id } })
    

    And inside the partial view, used this...

    @ViewBag.id

提交回复
热议问题