Partial View allows us to put HTML and C# code into a file that we can reuse across multiple other views. This is very useful when you work on a large application.
Assume we have the following peice of code that we would like to make reusable for other views.
We will extract the above marked code and paste it in a new "partial view" and then we'll just call that "partial view" from this foreach loop. Please use the following.
Step 1
Select the above code and copy it to the clipboard.
Step 2
Right-click on any view folder to create a new "partial view".
You can use any name for this view page but the underscore sign (_) is recommended to be used before the view name that represents something that is reusable. You also have the opportunity to select the "Model class" in the above dialog to create a strongly typed view. And remember to check the checkbox "Create as a partial view".
Step 3
Now, in the "partial view" page paste all the code you copied above. You may need to fix some errors here like @item.Name will become @Model.Name. Here is the complete code:
Step 4
One more thing, you need to place a reference at the location from where we copied the code, here you go:
Remember to pass the "partial view" name and model name. Now, run the application, your application will work the same because we just set up a new structure in the application.
Hope this helps.






gampa dugPosted Feb 27, 2024, 4:55 PM EST
It might be prudent to adhere to best naming convention standards. This helps to quickly identify things like _partialView.
Sanjay KumarPosted Sep 7, 2022, 2:19 AM EDT
Very good article
Josepch WillPosted Aug 1, 2021, 6:30 PM EDT
These options don't seem to appear for me. I am using Visual Studio 2019 Enterprise (I got a license key for this while I was working on my bachelors a few years back). I am working through a Udemy.com course and I don't really want to continue until I figure this out. There is no options for me to "create as a partial view" or "Use a layout page" which is another thing I need. Can anyone point out what I might be doing wrong or what changes I need to make to see this dialog?
Pankajkumar PatelPosted Jul 25, 2019, 7:26 PM EDT
Good article ...
Pratiksha VaishnavPosted Jun 9, 2019, 8:38 PM EDT
I want know if i edit a partial view then it will not reflected in output for new edited content.
Phoolchand PatelPosted May 10, 2018, 11:17 PM EDT
Good one to read...
Anil Kumar MurmuPosted Dec 15, 2016, 4:02 AM EST
Thank you for sharing the article.
Vinish KumarPosted Nov 16, 2016, 11:36 PM EST
Can You please explain how to use partial view in my view page
Vinish KumarPosted Nov 16, 2016, 11:35 PM EST
View Vs Partial View Which is nice one
SubashPosted Oct 26, 2016, 12:07 AM EDT
Nice one sir
Anu VPosted Oct 12, 2016, 4:33 AM EDT
Nice..
Umesh ApPosted Sep 19, 2016, 9:52 PM EDT
Good explanation but How can we access parent views control value in partial view? I need to access one of the controls value in partial view, please suggest.
Munesh SharmaPosted May 28, 2016, 12:37 AM EDT
nice
Bhuvanesh MohankumarPosted May 12, 2016, 6:02 AM EDT
Simple and Nice
Arbaz khanPosted Feb 28, 2016, 2:03 AM EST
Good one.....
Samir SanghaviPosted Feb 9, 2016, 7:31 PM EST
Thank You....!!
Rupali ShindePosted Jan 29, 2016, 12:18 AM EST
nice article sir
Ehsan SajjadPosted Jan 11, 2016, 5:23 AM EST
Keep Sharing more :)
Upendra Pratap ShahiPosted Nov 3, 2015, 3:02 AM EST
nice one sir...
Muni SekharPosted Aug 4, 2015, 9:08 AM EDT
good one
Kevin VarathaPosted Jun 25, 2015, 3:28 AM EDT
very nice
Gaurav JoshiPosted Jun 8, 2015, 5:58 AM EDT
good article thanks
Ankit SaxenaPosted Jun 5, 2015, 2:44 AM EDT
nice
Nilesh JadavPosted Jun 2, 2015, 11:29 PM EDT
Glad to get this information thanks Jignesh !
Sourabh SomaniTOP 100Posted May 31, 2015, 9:55 PM EDT
good one :)
Vivek TripathiPosted May 23, 2015, 9:19 PM EDT
nice :)
Manoj KulkarniPosted May 18, 2015, 12:12 AM EDT
Nice article. Thank you for sharing
Santhakumar MunuswamyPosted May 14, 2015, 11:27 AM EDT
Thanks for good one
Abhishek JaiswalPosted May 14, 2015, 2:40 AM EDT
Good one! :)
maheshPosted Mar 30, 2015, 5:13 AM EDT
check mvc4all.com for MVC5 Partial View comparing with this