The question
I've read several posts on the net about there being no real difference between a partial view and a regular view in ASP.NET MVC, only that the convention of using them was different. Is this really the case?
I decided to find out the details for myself as part of the new "MVC for Web Forms Developers" course I'm working on for pluralsight.com so I could see exactly what all this entailed outside of just being a convention difference. Let it be known, there is indeed several differences you should be aware of. This post isn't meant to state when you should use one vs the other, there are plenty of resources for that. Here we just want to delve into how they are different, which in turn can help you decide when to use a View vs PartialView (and to confuse things more the decision there is really View vs PartialView vs Html.Action vs Html.Partial vs Ajax in any combination)
The differences
The differences that were obvious from the code are
- Partial Views don't have a layout processed. Very important to know.
- Partial Views don't check for a _ViewStart.cshtml. Note this is typically where layouts are specified but technically you could specify one in your partial and it would be ignored. Very important to know.
- Partial Views can throw a slightly different exception, the details included to InvalidOperationException in PartialViewResult vs ViewResult classes. This is pretty minor.
There is a slight difference in how they are processed.
Lets look at the code, shall we?
First, the differences between a PartialViewResult and a ViewResult as contained in the following files from the MVC source code:
- c:\source\aspnetwebstack\src\System.Web.Mvc\PartialViewResult.cs (link to source here)
- c:\source\aspnetwebstack\src\System.Web.Mvc\ViewResult.cs (link to source here)
Lets dive into FindPartialView and FindView. These are the functions called when you "return View()" and "return Partial()" from inside a controller.
The comparison of PartialViewResult and ViewResult
First check out a comparison side by side, this may give you an easy quick view with one of the best tools of all time,Beyond Compare
The codez
public virtual ViewEngineResult FindPartialView(ControllerContext controllerContext, string partialViewName, bool useCache) { if (controllerContext == null) { throw new ArgumentNullException("controllerContext"); } if (String.IsNullOrEmpty(partialViewName)) { throw new ArgumentException(MvcResources.Common_NullOrEmpty, "partialViewName"); } string[] searched; string controllerName = controllerContext.RouteData.GetRequiredString("controller"); string partialPath = GetPath(controllerContext, PartialViewLocationFormats, AreaPartialViewLocationFormats, "PartialViewLocationFormats", partialViewName, controllerName, CacheKeyPrefixPartial, useCache, out searched); if (String.IsNullOrEmpty(partialPath)) { return new ViewEngineResult(searched); } //********* note the call here to CreatePartialView ***** return new ViewEngineResult(CreatePartialView(controllerContext, partialPath), this); } public virtual ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache) { if (controllerContext == null) { throw new ArgumentNullException("controllerContext"); } if (String.IsNullOrEmpty(viewName)) { throw new ArgumentException(MvcResources.Common_NullOrEmpty, "viewName"); } string[] viewLocationsSearched; string[] masterLocationsSearched; string controllerName = controllerContext.RouteData.GetRequiredString("controller"); string viewPath = GetPath(controllerContext, ViewLocationFormats, AreaViewLocationFormats, "ViewLocationFormats", viewName, controllerName, CacheKeyPrefixView, useCache, out viewLocationsSearched); string masterPath = GetPath(controllerContext, MasterLocationFormats, AreaMasterLocationFormats, "MasterLocationFormats", masterName, controllerName, CacheKeyPrefixMaster, useCache, out masterLocationsSearched); if (String.IsNullOrEmpty(viewPath) || (String.IsNullOrEmpty(masterPath) && !String.IsNullOrEmpty(masterName))) { return new ViewEngineResult(viewLocationsSearched.Union(masterLocationsSearched)); } //********* note the call here to CreateView ***** return new ViewEngineResult(CreateView(controllerContext, viewPath, masterPath), this); }
The differences in view processing
The function calls below to create a partial view or a regular view do indeed differ. One has a pipeline that uses a layout, the other doesn't. The regular view processing uses viewstart pages as well. For those unfamilar with the viewstart file, this is a file MVC looks for since MVC3.
MVC will look in the /Views/Shared folder and in the current view folder as well for a file named _ViewStart.cshtml. This file contains code that will be executed before the view is processed, typically it's used to store the path to the layout in it and again, can be set for all views or overridden in a particular views folder, ex /Views/Customer/_ViewStart.cshtml to set a different Layout for views in that folder as one example.
@{ Layout = "~/Views/Shared/_MasterPage.cshtml"; }
protected override IView CreatePartialView(ControllerContext controllerContext, string partialPath) { //**NOTE a partial view has a null layout and runViewStartPages is false! ** return new RazorView(controllerContext, partialPath, layoutPath: null, runViewStartPages: false, viewStartFileExtensions: FileExtensions, viewPageActivator: ViewPageActivator) { DisplayModeProvider = DisplayModeProvider }; } protected override IView CreateView(ControllerContext controllerContext, string viewPath, string masterPath) { //note the usage of a masterPath below. var view = new RazorView(controllerContext, viewPath, layoutPath: masterPath, runViewStartPages: true, viewStartFileExtensions: FileExtensions, viewPageActivator: ViewPageActivator) { DisplayModeProvider = DisplayModeProvider }; return view; }
In closing
So there are some differences as probably expected. Nothing groundbreaking but it is important to understand the shortcut pipeline the PartialView takes hence making them perform a bit better as well. Ok, now you know the exact differences and have seen it from the source, in other words - heard it from
Enjoy!
More informative subject.model view controller(MVC) is a framework for building web application and main part of asp.net. The Keshri Software Solutions provides Web Application development,Website Promotions, Search Engine Optimizations services . We have a very dedicated and hard working team of web application developers(asp.net/c#/sql server/MVC) , Search engine optimizers. Fast communication and quality delivery product is our commitment.
ReplyDeleteTo get more details please log on to - http://www.ksoftware.co.in .
ReplyDeleteThis is nice information,, Thanks for sharing this information,, Its very useful to me
software development
The article was awesomely described here by the author. I really enjoyed reading interesting post from this blog.
ReplyDeleteSoftware Development Company in Indore
Thanks for sharing it. Anar .NET Solutions
ReplyDeleteThis page is very beautiful.
ReplyDeletehttp://katagombal.weebly.com/
Thank you for sharing helpful information.
ReplyDeleteonline training
online software training
online business training inistitute
online marketing training institute
online music training
online designing training
online languages training
This comment has been removed by the author.
ReplyDeletepantun cinta
Deletekata mutiara
kata bijak
Informative and helpful post you have shared.
ReplyDeleteeCommerce website development in Chennai
kata bijak
ReplyDeletepantun jenaka
puisi cinta
Such a nice blog posting
ReplyDeleteMobile App Development Company Indore
شركة تسليك مجاري المطبخ بالرياض
ReplyDeleteشركة تسليك مجاري بالرياض
شركة تسليك مجارى الحمام بالرياض
level تسليك المجاري بالرياض
افضل شركة تنظيف بالرياض
تنظيف شقق بالرياض
شركة تنظيف منازل بالرياض
شركة غسيل خزنات بالرياض
افضل شركة مكافحة حشرات بالرياض
رش مبيدات بالرياض
شركة تخزين عفش بالرياض
شركة تنظيف مجالس بالرياض
تنظيف فلل بالرياض
ابى شركة تنظيف بالرياض
For Razor users, both regular and partial views are cshtml files. There is no actual difference between them.
ReplyDeleteWeb development company in Indore
I am very glad to read your blog post it’s very useful for everyone. I am completely satisfied with your blog.
ReplyDeleteE-commerce web Design Company in India
We welcome to Exoticdelhiescorts provide you with a hot Hyderabad model or girl that you can make love in Hyderabad.
ReplyDeletehttp://www.exoticdelhiescorts.in/call-girls-hyderabad.html
This is detailed and excellent information. Your blog is like professional! Do you want to find best premium wordpress templates for any kind of business? go here https://wordpresstemplates.ch/
ReplyDeleteReally great blog, it's very helpful and has great knowledgeable information. Thanks for sharing, keep updating such a good informative blog.
ReplyDeleteDigital Transformation Services | Austere Technologies
VERY INFORMATIVE BLOG. KEEP SHARING SUCH A GOOD ARTICLES.
ReplyDeletecloud Services | Austere Technologies
Really great blog, it's very helpful and has great knowledgeable information. Thanks for sharing, keep updating such a good informative blog.
ReplyDeleteBest Software Company | Austere Technologies
Very good informative article. Thanks for sharing such nice article, keep on up dating such good articles.
ReplyDeleteIOT SERVICES | INTERNET OF THINGS | Austere Technologies
Drivers for all kinds of devices: https://huaweidrivers.com/
ReplyDeleteLooking great article, contains very useful information. Thanks much for sharing and please do keep on sharing...
ReplyDeleteBest Online Software Training Institute | Asp.Net MVC Training
I am thankful to this blog for assisting me. I added some specified clues which are really important for me to use them in my writing skill. Really helpful stuff made by this blog.
ReplyDeleteทํา สติ๊กเกอร์ สินค้า
Hi Thanks for the nice information its very useful to read your blog. We provide best System Integration Services
ReplyDeleteHi Thanks for the nice information its very useful to read your blog. We provide best Chartered Accountancy
ReplyDeleteHi Thanks for the nice information its very useful to read your blog. We provide best Certified Financial Analyst
ReplyDeleteThank you for sharing this valuable information. But get out this busy life and find some peace with a beautiful trip. book ANDAMAN TOUR PACKAGE @24599
ReplyDeleteThank you for sharing this valuable information. But get out this busy life and find some peace with a beautiful trip. book BEST ANDAMAN HONEYMOON PACKAGE @5999
ReplyDeleteHi Thanks for the nice information its very useful to read your blog. We provide Software Development Services
ReplyDeleteHi Thanks for the nice information its very useful to read your blog. We provide best Chartered Institute Of Management Accountants
ReplyDeleteWomen and young women see the world specific way. They both have substitute point of view in understanding the world in an unexpected way. Furthermore, they interface with everybody shockingly. Young women are twelve, yet women are a need.
ReplyDeletegoa escort
Thanks for sharing this with so much of detailed information, its much more to learn from your article. Keep sharing such good stuff.
ReplyDeleteVIVO Mobile Service Center in Coimbatore
Sony Mobile Service Center in Coimbatore
Girls in South Delhi are well-renowned across India for their open mind and also stylish personality. Friendly, well-read and also fashionable, the South Delhi ladies are the ideal business for your leisure time, at your certain event Delhi Escort
ReplyDeleteExcellent informative blog, keep for sharing.
ReplyDeleteBest System Integration services | Massil Technologies
Thanks for posting this info. I just want to let you know that I just check out your site and I find it very interesting and informative. I can't wait to read lots of your posts.
ReplyDeleteTekSlate Online Training's
awesome post presented by you..your writing style is fabulous and keep update with your blogs.
ReplyDeletetop web designing companies in hyderabad
web designers in hyderabad
best website designing company in Hyderabad
Are you looking for escort advantage in Delhi, we give the best that would absolutely change your experience. Our escorts are arranged precisely to pass on best organization that you are scanning for.
ReplyDeleteDelhi Escorts
nice info...
ReplyDeleteThank you for sharing
Brolly- Training and marketing services | Digital marketing course with internship
Thanks for sharing the useful content please do keep on sharing…
ReplyDeleteSoftware Training courses in hyderabad | HTML course
ReplyDeleteWell said!! much impressed by reading your article. Keep writing more.
Software testing training in chennai
Salesforce Training in Chennai
Big Data Training in Chennai
Hadoop Training in Chennai
Android Training in Chennai
Selenium Training in Chennai
Digital Marketing Training in Chennai
JAVA Training in Chennai
Best JAVA Training institute in Chennai
The Post which you wrote is full of informative and vital blogs. I like it very much. Thank you for your work.
ReplyDeleteAngularJS Training in Chennai
AngularJS course in Chennai
AngularJS Training institute in Chennai
German Classes in Chennai
German Language Classes in Chennai
German Certification in Chennai
Very good to read thanks for sharing
ReplyDeletesalesforce training institute chennai
The eye-getting self-regulating escorts in Goa perceive how to make indisputably the most goal and to an extraordinary Goa Escorts degree key minutes for the clients. On the off chance that a man needing to get an entire night with Goa escort, atthat point he would be a head among the most respected men. The contact females inGoaare intriguing, eye-getting and unimaginable from each perspective
ReplyDeleteThank you for your post. This is excellent information.
ReplyDeleteCEH Training In Hyderbad
I really appreciate your efforts. I found this article quite interesting and informative especially the quality of content that I have read here really inspire me. I have found another blog for the same quality content
ReplyDeleteDigital Marketing in Bhopal
Everybody has to take the services of a girl like Vida, when the company may be available for every girl of her time, which is also found in the Bangalore City May, which will serve you. Plz you can visit to Mg.Road , Bangalore and the direct call to me : 7022789089
ReplyDeletehttps://www.payalpandya.com
bangalore escorts
escorts in Bangalore
bangalore escorts service
bangalore escorts agency
escort service in bangalore
bangalore escort girls
escorts service bangalore
Nice post, very useful blogs with very useful information, thank you for sharing this post web application development company
ReplyDeleteEverything is very open with a very clear clarification of the issues. It was truly informative. Your website is useful. Many thanks for sharing! Take a look also at web development and web development company
ReplyDeleteOnly one out of every odd female escort for social event in Hyderabad offer their butt for some butt-driven, so guarantee before the get-together comes that everything has been shown all together for both of you to appreciate.
ReplyDeleteHyderabad Escorts
Independent Call Girl in Hyderabad
Good post..Keep on sharing....
ReplyDeleteGCP Training
Google Cloud Platform Training
GCP Online Training
Google Cloud Platform Training In Hyderabad
good Post Really its informative and thanks for sharing with us
ReplyDeleteSarkari Naukri UP Government
Sarkari Jobs 12th Pass
Jobs in Assam
Superlative efficient Goa escort organizations offer a wide scope of selective administrations from a high social class. These closeness can made everything from giving you an accomplice for a conference, most prominent undertakings travel visits. Would you like to make the most of your get-away? Take a journey with an attractive lady or simply appreciate a night around the city
ReplyDeleteGoa Escorts
This is really great informative blog. Keep sharing.
ReplyDelete.Net Training In Ahmedabad
Live Project Training in .Net
hello reshab here please follow our link for all vip escorts in bangalore complete details best escort service in bangalore
ReplyDeletebest escort service in bangalore
escort service in bangalore
escort in bangalore
escort bangalore
bangalore escort
Hey Really Thanks for sharing the best information regarding oracle,hope you will write more great blogs.
ReplyDeleteWorkday Online Training
https://n4g.com/user/score/nothingstopusnow
ReplyDeletehttps://dergipark.gov.tr/@andybern
https://www.bookcrossing.com/mybookshelf/tattoosboygirl?
http://profile.cheezburger.com/tattoosboygirl/
http://twubs.com/tattoosboygirl
https://topibestlist.com/
https://n4g.com/user/score/nothingstopusnow
ReplyDeletehttps://dergipark.org.tr/@andybern
https://www.bookcrossing.com/mybookshelf/tattoosboygirl?
http://profile.cheezburger.com/tattoosboygirl/
http://twubs.com/tattoosboygirl
https://topibestlist.com/
This is a nice article here with some useful tips for those who are not used-to comment that frequently. Thanks for this helpful information I agree with all points you have given to us. I will follow all of them.
ReplyDeleteapache spark online training
Trucking Cube Provide Freight Charges, Lorry hires Bulk Transport, Cheapest Truck Rental Company, Hire a Truck, etc. If you want this kind of services at an affordable cost then contact Trucking Cube.
ReplyDeleteInternational Freight Forwarders
Truck Hire
Budget Moving Truck
This is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.
ReplyDeletejava training in Bangalore