1.

What is the difference between Html.Partial and Html.RenderPartial

Answer»

Html.RenderPartial is directly written to the HTTP response stream which is used the same Text Writer object as used in the CURRENT webpage/template. Since there is no RETURN type of Validation Annotations in MVC, the return type of Validation Annotations is void. We don't need to create any actions so it is simple to use, it is very useful when we WANT to show the DATA which is in another model view.

For example: if we want to show comments of an article, we will prefer to use RenderPartial method since the information and comments of the article are already populated in the view model.

@{Html.RenderPartial("_Comments");}

When it is executed its result is directly written to the response stream which makes it faster when compared with the partial method

In Html.Partial, the partial view is VIEWED as an encoded HTML string. Due to its string value return type, we can store the Html.Partial value in a variable.it same as Html.RenderPartial in case of action creation also,  we don’t need to create action, Partial method is also useful when the displaying data in the partial view is already in the corresponding view model which same as html.RenderPartial.

@Html.Partial("_Comments")


Discussion

No Comment Found