In this article, I describe Different between Partial and RenderPartial in asp.net mvc. Both of these helper methods are used to render a partial views.
The return type of RenderPartial is Void, where as Partial return MvcHtmlString.
InvokePartial View(in Razor View):
@Html.Partial("Partial viewName", Model)
InvokePartial View(in Aspx View):
<%: Html.Partial("Partial viewName", Model)%>
InvokeRenderPartial View(In Razor View):
{Html.RenderPartial("Partial viewName", Model);}
InvokeRenderPartial View(in Aspx View):
<% Html. RenderPartial("Partial view Name", Model); %>
Example
@Html.Partial("_Product", item)
{Html.RenderPartial("_Product", item);}
The main difference is that RenderPartial() returns void and the output will be written directly to the output stream, where as Partial() returns MvcHtmlString which can be assigned to a variable and manipulate it if required. So when there is a need to assign the output to a variable for manipulating it, then use Partial() else use RenderPartial(). RenderPartial() is better performance over partial().
Post your comments / questions
Recent Article
- How to Enable Virtualization in BIOS Security Settings in Intel Processors For Android Studio?
- Dependency 'androidx.activity:activity:1.8.0' requires libraries and applications that depend on it.
- AttributeError: 'NoneType' object has no attribute 'get_text' - Python
- ModuleNotFoundError: No module named 'openpyxl' - Python
- How to get thumbnail from vimeo video URL in Python?
- Remove all special characters, punctuation except spaces from string - Python
- OSError: cannot write mode RGBA as JPEG- Python
- expected str, bytes or os.PathLike object, not JpegImageFile - Python
Related Article