ASP. Net core MVC Partial and HTML Renderpartial is an output HTML fragment, but the difference is:

  • Html. When partial, the partial view is rendered as a string, which directly generates a string from the view content and returns it, which is equivalent to an escape process.
  • Html. Renderpartial is to write the distribution view directly into the response output stream, that is, the current httpcontext. Because it is direct output, it has good performance and little impact. Therefore, it can only be placed directly in the code block, not in the expression, because the return value is void.

Therefore, they are used in different ways in the view:

@Html.Partial("_PartialView")
@{Html.RenderPartial("_PartialView");}

It should be noted that generally, it is OK to output the page according to the above method, but when judging to output a certain view according to the actual demand in the page, HTML needs to be used Renderpartial method, such as:

if(isAdminHeader)
{
    Html.RenderPartial("AdminHeader")
} 
else
{
    Html.RenderPartial("Header")
}

If using HTML Partial may be ignored by the bottom layer, resulting in the problem of not entering this view

All Comments

Leave a Reply Cancel Reply

Tips: Your email address will not be disclosed!

If you can't see clearly,please click to change...