Interviews - C# Corner

Yogesh Bajpai
What is difference between @Html.Partial and @Html.RenderPartial ?
By Yogesh Bajpai in ASP.NET MVC onFeb 03 2014
  • Manju lata Yadav
    Jul, 2014 9

    The main difference is that "RenderPartial" returns void and output will be written directly to the output sream, where as the "Partial" returns MvcHtmlString which can be assigned to a variable and manipulate it if required. So, when there is no need to assign the output to a variable for manipulating it, then use Partial, else use RenderPartial. Renderpartial does exactly the same thing and is better for performance over partial().

    • 5
  • Shweta Lodha
    Feb, 2014 5

    Html.Partial returns a String, Html.RenderPartial calls Write internally, and returns void. The basic usage is: // Razor syntax @Html.Partial("ViewName") @{ Html.RenderPartial("ViewName"); } // WebView syntax <%: Html.Partial("ViewName") %> <% Html.RenderPartial("ViewName"); %> In the snippet above, both calls will yield the same result. While one can store the output of Html.Partial in a variable or return it from a method, one cannot do this with Html.RenderPartial. The result will be written to the Response stream during execution/evaluation.

    • 3
  • Anupam Singh
    Jul, 2014 1

    The main difference between Partial and RenderPartial is : Partial return string and write it to document as Shweta said . RenderPartial actually write direct to context response.

    • 2
  • Vishal Lodha
    Feb, 2015 12

    // Html.RenderPartial(1) This method result will be directly written to the HTTP response stream means it used the same TextWriter object as used in the current webpage/template.(2) This method returns void.(3) Simple to use and no need to create any action.(4) RenderPartial method is useful used when the displaying data in the partial view is already in the corresponding view model.For example : In a blog to show comments of an article, we would like to use RenderPartial method since an article information with comments are already populated in the view model.EX: @{Html.RenderPartial("_Comments");}(5) This method is faster than Partial method since its result is directly written to the response stream which makes it fast.// Html.Partial(1) Renders the partial view as an HTML-encoded string.(2) This method result can be stored in a variable, since it returns string type value.(3) Simple to use and no need to create any action.(4) Partial method is useful used when the displaying data in the partial view is already in the corresponding view model.For example : In a blog to show comments of an article, we would like to use RenderPartial method since an article information with comments are already populated in the view model.EX: @Html.Partial("_Comments")

    • 1
  • Yogesh Bajpai
    Nov, 2014 16

    Which one is better ?

    • 1
  • Munesh Sharma
    Apr, 2014 12

    http://www.youtube.com/watch?v=0fYzD-SUW0I

    • 1
  • praveen singh
    Aug, 2019 22

    Html.Partial injects the html string of the partial view into the main view.
    Html.RenderPartial writes html in the response stream.

    • 0
  • Hamid Khan
    Jan, 2018 14

    Here is what I have found:Use RenderAction when you do not have a model to send to the view and have a lot of html to bring back that doesn't need to be stored in a variable.Use Action when you do not have a model to send to the view and have a little bit of text to bring back that needs to be stored in a variable.Use RenderPartial when you have a model to send to the view and there will be a lot of html that doesn't need to be stored in a variable.Use Partial when you have a model to send to the view and there will be a little bit of text that needs to be stored in a variable.RenderAction and RenderPartial are faster.

    • 0
  • Amit Kumar
    Mar, 2017 17

    @Html.RenderPartial("_OrderPage") is better than @Html.Partial("_OrderPage")

    • 0
  • Amit Kumar
    Mar, 2017 17

    Html.RenderPartial1.Html.RenderPartial: This method result will be directly written to the HTTP response stream means it used the same Text Writer object as used in the current webpage/template. 2.This method returns void. 3.Simple to use and no need to create any action. 4.RenderPartial method is useful when the displaying data in the partial view is already in the corresponding view model. For example : In a blog to show comments of an article, we would like to use Render Partial method since an article information with comments are already populated in the view model. @{Html.RenderPartial("_Comments");} 5.This method is faster than Partial method since its result is directly written to the response stream which makes it fast.Html.Partial1. Renders the partial view as an HTML-encoded string. 2. This method result can be stored in a variable, since it returns string type value. 3. Simple to use and no need to create any action. 4. Like Render Partial method, Partial method is also useful when the displaying data in the partial view is already in the corresponding view model. . @Html.Partial("_Comments")For Performance : @Html.RenderPartial("_OrderPage") is better than @Html.Partial("_OrderPage")

    • 0
  • Rajkumar Rajigounder
    Apr, 2015 1

    Thanks Guys.

    • 0

Most Popular Companies

Most Popular Job Functions

MOST LIKED QUESTIONS