Difference between View and PartialView in Asp.net MVC
I have seen a lots of debates and discussions on Difference between View and PartialView in Asp.net MVC. Both are used to return Html but main difference is that View return whole page including Layout while PartialView return only piece of html content. Beside all these points, I made some remarks on difference between view and partialview and some interesting analysis based on return type of view and partialview are described here.
Key Difference between view and partialview in Asp.net mvc
- Partialview generally does not have any Layout while view content Layout.
- Partialview mostly does not content html attribute like head , tag , meta and body while view can have all this attribute
- Partialview is reusable content which is render inside view(parent page)
- Partialview mostly used with Ajax request to process fast and update particular portion while view load whole page.
- Partialview generally process with mvc Ajax.ActionLink and Ajax.Beginform while View process with mvc Html.ActionLink and Html.Beginform
But above point are not always true for view vs partialview, as I have experienced its practically with different return types and appying layout or not. My analysis with some interesting results, while comparing view and partialview as below.
Return view and partialview with or without Layout Result
- Return View + Layout = View
- Return View – Layout = View (if Layout specified in _ViewState.cshtml)
- Return View – Layout = PartialView (if Layout not specified in _ViewState.cshtml)
- Return PartialView + Layout = View
- Return PartialView – Layout = PartialView
What is your opinion ?
Here we have discussed view vs partiaview in asp.net mvc. I hope it will be very useful to you. If you have any query and question, you can comment or you can mail me.