{"id":39148,"date":"2016-08-30T14:09:11","date_gmt":"2016-08-30T08:39:11","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=39148"},"modified":"2016-09-01T10:28:39","modified_gmt":"2016-09-01T04:58:39","slug":"create-partial-view-in-mvc-in-asp-net-and-integrate-as-a-reusable-component-in-umbraco-cms","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/create-partial-view-in-mvc-in-asp-net-and-integrate-as-a-reusable-component-in-umbraco-cms\/","title":{"rendered":"Create Partial View in MVC in Asp.Net and integrate as a reusable component in Umbraco CMS."},"content":{"rendered":"<p><strong>What is Partial View in MVC: &#8211;<\/strong><\/p>\n<p>Partial view is same as a user control in Web Form application in <strong>Asp.Net<\/strong> .So it can be reused with in multiple views in MVC. Partial Views are special views which render a portion of View content.<\/p>\n<p>Step by step process to implement partial views in MVC in Asp.net and integrate with <a href=\"http:\/\/www.tothenew.com\/blog\/how-to-integrate-asp-net-custom-user-control-with-umbraco-cms\/\">Umbraco<\/a> CMS in Asp.Net:-<\/p>\n<p>Given below partial view example will demonstrate to display contact list in Partial view as:-<\/p>\n<p><strong>Step 1:- Inside Visual Studio add model as given below screen shots:-<\/strong><\/p>\n<p><strong>A)<\/strong>\u00a0In\u00a0<strong>Solution Explorer of visual studio<\/strong><strong>, <\/strong>right click on the\u00a0<em>Models<\/em>\u00a0folder, select<strong>\u00a0<\/strong><strong>Add<\/strong><strong>, <\/strong>and then select<strong>\u00a0<\/strong><strong>Class<\/strong><strong>.<\/strong><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone  wp-image-39138\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/08\/SImg1-300x153.png\" alt=\"SImg1\" width=\"373\" height=\"190\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/08\/SImg1-300x153.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/08\/SImg1.png 580w\" sizes=\"(max-width: 373px) 100vw, 373px\" \/><\/p>\n<p><strong>B)<\/strong>\u00a0Give appropriate name for the class as given below screen shot:-<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-39139\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/08\/SImg2-300x154.png\" alt=\"SImg2\" width=\"300\" height=\"154\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/08\/SImg2-300x154.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/08\/SImg2.png 556w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p><strong>\u00a0 \u00a0 \u00a0 C)<\/strong>\u00a0Add the three properties to theContactFormViewModel class as in given below screen shot which is created as in above screen shot<strong>:<\/strong><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-39140\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/08\/SImg3-300x175.png\" alt=\"SImg3\" width=\"300\" height=\"175\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/08\/SImg3-300x175.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/08\/SImg3.png 396w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p><strong>Step 2:- Add Partial View<\/strong><\/p>\n<p><strong>A)<\/strong>\u00a0In\u00a0<strong>Solution Explorer of visual studio<\/strong><strong>, <\/strong>right click on the\u00a0<em>Views=&gt;Partials<\/em> folder, select<strong>\u00a0<\/strong><strong>Add<\/strong><strong>,\u00a0<\/strong>and then select<strong>\u00a0<\/strong><strong>View<\/strong><strong>.<\/strong><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-39141\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/08\/SImg4-300x142.png\" alt=\"SImg4\" width=\"300\" height=\"142\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/08\/SImg4-300x142.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/08\/SImg4.png 556w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p><strong>\u00a0 \u00a0 B)<\/strong>\u00a0Give appropriate name for the View , select Model class and checked create as a partial view checkbox as given below screen shot:-<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-39142\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/08\/SImg5-300x170.png\" alt=\"SImg5\" width=\"300\" height=\"170\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/08\/SImg5-300x170.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/08\/SImg5.png 556w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p><strong>\u00a0 \u00a0 \u00a0 C)<\/strong>\u00a0Write the following HTML code using razor for displayingcontact list<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-39143\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/08\/SImg6-300x160.png\" alt=\"SImg6\" width=\"300\" height=\"160\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/08\/SImg6-300x160.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/08\/SImg6.png 491w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p><strong>Step 3:- Add Controller with Umbraco CMS reference<\/strong><\/p>\n<p><b>\u00a0 \u00a0 \u00a0 \u00a0A)<\/b> Adding Umbraco CMS reference<\/p>\n<p><span style=\"font-weight: 400\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0In<\/span><b>\u00a0<\/b><span style=\"font-weight: 400\">Solution Explorer of visual studio<\/span><b>, <\/b><span style=\"font-weight: 400\">right click on the\u00a0Bin folder, select<\/span><b>\u00a0Manage NuGet Packages, <\/b><span style=\"font-weight: 400\">and then install Umbraco CMS reference<\/span><b>.<\/b><\/p>\n<p><b><b>\u00a0 \u00a0 \u00a0 B) <\/b><\/b>Adding Controller<\/p>\n<p><span style=\"font-weight: 400\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <strong>1)<\/strong> \u00a0In<\/span><b>\u00a0<\/b><span style=\"font-weight: 400\">Solution Explorer of visual studio<\/span><b>, <\/b><span style=\"font-weight: 400\">right click on the\u00a0Controllers folder, select<\/span><b>\u00a0Add,\u00a0<\/b><span style=\"font-weight: 400\">and then select <\/span><b>Controller.<\/b><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-39144\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/08\/SImg7-300x115.png\" alt=\"SImg7\" width=\"300\" height=\"115\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/08\/SImg7-300x115.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/08\/SImg7.png 569w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p><strong> 2)<\/strong>\u00a0<strong><span style=\"font-weight: 400\">Give appropriate name for theController as given below screen shot:-<\/span><\/strong><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone  wp-image-37567\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/07\/SImg8.png\" alt=\"SImg8\" width=\"517\" height=\"165\" \/><\/p>\n<p><strong>C)<\/strong>\u00a0Add action(method) in this controller:<\/p>\n<p><strong><span style=\"font-weight: 400\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0This controller (ContactFormSurfaceController) inherited by surface controller class not controller class. And <\/span><span style=\"font-weight: 400\">this action return as partial view using following method.<\/span><\/strong><\/p>\n<p><strong><b>PartialView(your view Name, Model Name)<\/b><\/strong><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-37568\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/07\/SImg9.png\" alt=\"SImg9\" width=\"472\" height=\"233\" \/><\/p>\n<p><b>Step 4:- Integrate this partial view component with umbraco CMS<\/b><\/p>\n<p><span style=\"font-weight: 400\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0First build this Project then add Project DLL in Umbraco bin folder and Partial view in Views=&gt; Partial folder in umbraco CMS.<\/span><\/p>\n<p><b>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 How to call Partial view in umbraco CMS Page ?<\/b><\/p>\n<p><strong>\u00a0 \u00a0 A)<\/strong>\u00a0Call Partial View on your umbraco page<\/p>\n<p><span style=\"font-weight: 400\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0For calling partial view we will write following code on the umbraco page. <\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0@Html.Action(Action Name,Controller Name)<\/span><\/p>\n<p><b>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0For Example:-<\/b><\/p>\n<p><strong><span style=\"font-weight: 400\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0@Html.Action(&#8220;ContactList&#8221;,&#8221;ContactFormSurface&#8221;)<\/span><\/strong><\/p>\n<p><strong>\u00a0 \u00a0B)<\/strong>\u00a0<strong><span style=\"font-weight: 400\">Browse umbraco page in the browser and it will be showing contact list as below \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 screenshot<\/span><\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-37569\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/07\/SImg10.png\" alt=\"SImg10\" width=\"322\" height=\"168\" \/><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is Partial View in MVC: &#8211; Partial view is same as a user control in Web Form application in Asp.Net .So it can be reused with in multiple views in MVC. Partial Views are special views which render a portion of View content. Step by step process to implement partial views in MVC in [&hellip;]<\/p>\n","protected":false},"author":855,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":31},"categories":[1],"tags":[2222],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/39148"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/855"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=39148"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/39148\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=39148"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=39148"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=39148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}