Populate a Razor Section From a Partial

前端 未结 12 1506
不知归路
不知归路 2020-11-27 11:23

My main motivation for trying to do this is to get Javascript that is only required by a partial at the bottom of the page with the rest of the Javascript and not in the mid

12条回答
  •  萌比男神i
    2020-11-27 11:43

    The more elegant way to do this is to move partial view scripts into separate file and then render it in Scripts section of view:

    This is the view

    @Html.RenderPartial("_Partial") @section Scripts { @Html.RenderPartial("_PartialScripts") }

    The partial view _Partial.cshtml:

    This is the partial.

    The partial view _PartialScripts.cshtml with scripts only:

    
    

提交回复
热议问题