Html.Partial vs Html.RenderPartial & Html.Action vs Html.RenderAction. can any one please describe the difference
Asked Answered
S

1

6

In ASP.NET MVC, what is the difference between:

Html.Partial and Html.RenderPartial
Html.Action and Html.RenderAction
Stephanistephania answered 15/5, 2015 at 10:45 Comment(6)
i just want to know why we would use one over another?Stephanistephania
Check this link, it should answer your questionGrilled
In fact I did an answer with short summary of what this link talks aboutGrilled
thank you so much your link was helpful. but can you how can i implement partial views on one master page, if i have two different partial views and i have included them in "<div>" tag and now i want only one to be visible on selection of particular drop down List option.Stephanistephania
Refer here = #5248683Adaiha
alas the link by Andrei is no longer validOverride
G
15

Html.Action invokes the controller's action, which means it instantiates the controller entity, calls an action method, which builds a model an returns a view result.

Html.Partial uses already created model (or can be called without model at all) to render a specified view.

When to use one over the other? If you already have a model and just want to have a reusable view, opt to Html.Partial. If you see that some piece deserves its own model and action, maybe it makes sense to use Html.Action.

This question is discussed in much greater details in this article, and what you see above is basically an excerpt from it.

Grilled answered 15/5, 2015 at 11:13 Comment(2)
alas the link to the article is no longer validOverride
@ckapilla, thanks, fixed now. Kudos to awesome wayback machine projectGrilled

© 2022 - 2024 — McMap. All rights reserved.