Reputation: 3587
Both seem to allow you to take a section of a master layout and place it in another child file. I've been using RenderSection and then defining the section in the child files but I'm starting to wonder if this is not "best practice".
What is the difference between Html.Partial and RenderSection in a Razor MVC document?
Upvotes: 1
Views: 1034
Reputation: 6060
Html.Partial renders a partial view. This is another razor view that you want to embed within the main view.
RenderSection is done in a layout template to mark a "stub" where certain code would go.
Typically you use Html.Partial to render reusable pieces of code into multiple pages-- such as a complex user-control.
You would normally use RenderSection in your layout to have the layout decide WHERE certain content goes in the output, and the section in the view that is being rendered determines WHAT that content is. A common use is to allow your views define scripts that that layout then places at the bottom of the html body after footers and things defined in the layout.
Upvotes: 6