Home » ASP » ASP.MVC » RenderPartial vs RenderAction

RenderPartial vs RenderAction

ASP.NET MVC website describe pretty well the difference between the two. RenderPartial is used to display a reusable part of within the same controller and RenderAction render an action from any controller. They both render the Html and doesn’t provide a String for output.

Here is a picture that illustrate the difference between RenderPartial and RenderAction in Asp Mvc .Net.

If you need to have a String, which can be the case if you need to return by Ajax the content in Html you should use Html.Partial or Html.Action. They both create the view but instead of rendering it directly into the Http Response will produce an Html string which could be returned to be loaded into a div with Javascript or JQuery.

$('#result').load('http://localhost/myApp/User/Profile/1');

This is a small example where the action Profile of the controller User could return directly a String. To be able to generate this output server side, it would require that the Profile action return ContentResult type that will be generated by Html.Partial or Html.Action.

If you like my article, think to buy my annual book, professionally edited by a proofreader. directly from me or on Amazon. I also wrote a TypeScript book called Holistic TypeScript

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.