Data Haunting

Easy Solutions Destination

By

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

  1. Partialview generally does not have any Layout while view content Layout.
  2. Partialview mostly does not content html attribute like head , tag , meta and body while view can have all this attribute
  3. Partialview is reusable content which is render inside view(parent page)
  4. Partialview mostly used with Ajax request to process fast and update particular portion while view load whole page.
  5. 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

  1. Return View + Layout = View
  2. Return View – Layout = View (if Layout specified in _ViewState.cshtml)
  3. Return View – Layout = PartialView (if Layout not  specified in _ViewState.cshtml)
  4. Return PartialView + Layout = View
  5. 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.

Leave a Reply