Passing data from Partial View to its parent View

前端 未结 5 1436
旧巷少年郎
旧巷少年郎 2020-12-19 06:45

If I have a View and a Partial View, is there any way that I can pass data from the Partial View to the parent?

So if I have View.cshtml:



        
5条回答
  •  隐瞒了意图╮
    2020-12-19 07:17

    The simpler thing you could do is in _PartialView.cshtml:

    @model dynamic
    @{ 
        Model.Stuff = "stuff things";
    }
    

    and in parent view:

    @{ 
        Html.RenderPartial("_PartialView", (object) ViewBag);
    }
    

    then in parent view you can use:

    @ViewBag.Stuff
    

提交回复
热议问题