MVC Html.Partial or Html.Action

后端 未结 2 1706
夕颜
夕颜 2020-11-28 03:54

I am new to asp.net MVC so please bear with me. I need build a menu that repeats across multiple views. What would better serve the purpose Html.Action OR Html.Partial.

2条回答
  •  有刺的猬
    2020-11-28 04:46

    Here are what I consider my guidelines on using Html.Action or Html.Partial

    Html.Partial

    1. Use Html.Partial when you are rendering static content or,
    2. If you are going to pass data from the ViewModel that is being sent to the main view

    Html.Action

    1. Use Html.Action when you actually need to retrieve additional data from the server to populate the partial view

    Basically, if is static, use Html.Partial(). If dynamic, model independent data, use Html.Action(). There are probably more scenarios, but this will give you a good idea of where/how to go. Html.RenderPartial() and Html.RenderAction() are interchangeable for the similarly named functions above.

提交回复
热议问题