{"id":1618,"date":"2016-02-02T20:57:52","date_gmt":"2016-02-03T01:57:52","guid":{"rendered":"http:\/\/andrewpallant.ca\/wordpress\/?p=1618"},"modified":"2020-01-10T11:23:34","modified_gmt":"2020-01-10T16:23:34","slug":"loading-mvc-partials-using-jquery","status":"publish","type":"post","link":"http:\/\/andrewpallant.ca\/wordpress\/loading-mvc-partials-using-jquery\/","title":{"rendered":"Dynamically Load MVC Partials Using jQuery"},"content":{"rendered":"<p>Normally I do my examples in C#, but lately I have noticed a lack of VB.NET examples. Therefore, this example is in VB.NET.<\/p>\n<p>I have searched long and hard to find a way to dynamically load MVC partials.  I had tried to find a solution a few times, but quickly gave up.  I figured there must be a way. Then I remembered how I used to create on the fly images using an HTML image control and simple URL to an ASPX page which served up the image ( another blog topic ). Through this latest realization and a little searching I have pieced together a working model.  The piece I was missing was having the controller <strong>return a PartialView<br \/>\n<\/strong>.<!--more--><\/p>\n<p>To dynamically load a MVC partial, you first need to create a main view with a div content properly defined with a unique ID (index.vbhtml).<\/p>\n<pre>\r\n&lt;h1&gt;Main Content&lt;h1&gt;\r\n&lt;div id=\"divListOfStuffPartial\"&gt;\r\n\r\n&lt;\/div&gt;\r\n<\/pre>\n<p>Then you will need to create your partial that you want to load dynamically (ListOfStuff.vbhtml).<\/p>\n<pre>\r\n&lt;h1&gt;Make this content Dynamic&lt;h1&gt;\r\n&lt;div&gt;\r\n     &lt;div&gt;\r\n          &lt;li&gt;Item 1&lt;\/li&gt;\r\n          &lt;li&gt;Item 2&lt;\/li&gt;\r\n     &lt;\/div&gt;\r\n&lt;\/div&gt;\r\n<\/pre>\n<p>Create a controller with two methods. One to load the main view and one that you will use to load the dynamic partial (HomeController.vb).<\/p>\n<pre>Namespace Controllers\r\n    Public Class HomeController\r\n        Inherits Controller\r\n\r\n        Function Index() As ActionResult\r\n            Return View()\r\n        End Function\r\n\r\n        Function ListOfStuff() As ActionResult\r\n            Return PartialView()\r\n        End Function\r\n    End Class\r\nEnd Namespace\r\n<\/pre>\n<p>The loading of the partial is now easy and can be done using a jQuery statement.  Put the code either in the main view or a JS file that is referenced in the main view.<\/p>\n<pre>    function loadList()\r\n    {\r\n        $(\"#divListOfStuffPartial\").load( \"@(Html.Raw(Url.Action(\"ListOfStuff\", \"Home\")))\");\r\n    }();\r\n<\/pre>\n<p>Tah-Dah! We Are done.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Normally I do my examples in C#, but lately I have noticed a lack of VB.NET examples. Therefore, this example is in VB.NET. I have searched long and hard to find a way to dynamically load MVC partials. I had tried to find a solution a few times, but quickly gave up. I figured there &hellip; <a href=\"http:\/\/andrewpallant.ca\/wordpress\/loading-mvc-partials-using-jquery\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Dynamically Load MVC Partials Using jQuery<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[149,96],"tags":[236,196],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v23.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\r\n<title>Dynamically Load MVC Partials Using jQuery - LDNDeveloper<\/title>\r\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\r\n<link rel=\"canonical\" href=\"http:\/\/andrewpallant.ca\/wordpress\/loading-mvc-partials-using-jquery\/\" \/>\r\n<meta property=\"og:locale\" content=\"en_US\" \/>\r\n<meta property=\"og:type\" content=\"article\" \/>\r\n<meta property=\"og:title\" content=\"Dynamically Load MVC Partials Using jQuery - LDNDeveloper\" \/>\r\n<meta property=\"og:description\" content=\"Normally I do my examples in C#, but lately I have noticed a lack of VB.NET examples. Therefore, this example is in VB.NET. I have searched long and hard to find a way to dynamically load MVC partials. I had tried to find a solution a few times, but quickly gave up. I figured there &hellip; Continue reading Dynamically Load MVC Partials Using jQuery\" \/>\r\n<meta property=\"og:url\" content=\"http:\/\/andrewpallant.ca\/wordpress\/loading-mvc-partials-using-jquery\/\" \/>\r\n<meta property=\"og:site_name\" content=\"LDNDeveloper\" \/>\r\n<meta property=\"article:published_time\" content=\"2016-02-03T01:57:52+00:00\" \/>\r\n<meta property=\"article:modified_time\" content=\"2020-01-10T16:23:34+00:00\" \/>\r\n<meta name=\"author\" content=\"ldnDeveloper\" \/>\r\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\r\n<meta name=\"twitter:creator\" content=\"@LdnDeveloper\" \/>\r\n<meta name=\"twitter:site\" content=\"@LdnDeveloper\" \/>\r\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"ldnDeveloper\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\r\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"http:\/\/andrewpallant.ca\/wordpress\/loading-mvc-partials-using-jquery\/#article\",\"isPartOf\":{\"@id\":\"http:\/\/andrewpallant.ca\/wordpress\/loading-mvc-partials-using-jquery\/\"},\"author\":{\"name\":\"ldnDeveloper\",\"@id\":\"https:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/f6f5bb1ac3e0c5a54a8b5ce35fd67b84\"},\"headline\":\"Dynamically Load MVC Partials Using jQuery\",\"datePublished\":\"2016-02-03T01:57:52+00:00\",\"dateModified\":\"2020-01-10T16:23:34+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\/\/andrewpallant.ca\/wordpress\/loading-mvc-partials-using-jquery\/\"},\"wordCount\":232,\"publisher\":{\"@id\":\"https:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/f6f5bb1ac3e0c5a54a8b5ce35fd67b84\"},\"keywords\":[\"DotNet\",\"MVC\"],\"articleSection\":[\"jQuery\",\"Web\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/andrewpallant.ca\/wordpress\/loading-mvc-partials-using-jquery\/\",\"url\":\"http:\/\/andrewpallant.ca\/wordpress\/loading-mvc-partials-using-jquery\/\",\"name\":\"Dynamically Load MVC Partials Using jQuery - LDNDeveloper\",\"isPartOf\":{\"@id\":\"https:\/\/andrewpallant.ca\/wordpress\/#website\"},\"datePublished\":\"2016-02-03T01:57:52+00:00\",\"dateModified\":\"2020-01-10T16:23:34+00:00\",\"breadcrumb\":{\"@id\":\"http:\/\/andrewpallant.ca\/wordpress\/loading-mvc-partials-using-jquery\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/andrewpallant.ca\/wordpress\/loading-mvc-partials-using-jquery\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/andrewpallant.ca\/wordpress\/loading-mvc-partials-using-jquery\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/andrewpallant.ca\/wordpress\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Dynamically Load MVC Partials Using jQuery\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/andrewpallant.ca\/wordpress\/#website\",\"url\":\"https:\/\/andrewpallant.ca\/wordpress\/\",\"name\":\"LDNDeveloper\",\"description\":\"Learning, Growing and Sharing.\",\"publisher\":{\"@id\":\"https:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/f6f5bb1ac3e0c5a54a8b5ce35fd67b84\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/andrewpallant.ca\/wordpress\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/f6f5bb1ac3e0c5a54a8b5ce35fd67b84\",\"name\":\"ldnDeveloper\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/andrewpallant.ca\/wordpress\/wp-content\/uploads\/2017\/05\/cropped-AAEAAQAAAAAAAAXQAAAAJDQxMGRlMzFjLWM4ODctNDk1NC05M2EyLWE1NDNhNTRiZjVlYw-2.jpg\",\"contentUrl\":\"https:\/\/andrewpallant.ca\/wordpress\/wp-content\/uploads\/2017\/05\/cropped-AAEAAQAAAAAAAAXQAAAAJDQxMGRlMzFjLWM4ODctNDk1NC05M2EyLWE1NDNhNTRiZjVlYw-2.jpg\",\"width\":512,\"height\":512,\"caption\":\"ldnDeveloper\"},\"logo\":{\"@id\":\"https:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/image\/\"},\"description\":\"Andrew Pallant (@LdnDeveloper) has been a web, database and desktop developer for over 16 years. Andrew has worked on projects that ranged from factory automation to writing business applications. Most recently he has been heavily involved in various forms for ecommerce projects. Over the years Andrew has worn many hats: Project Manager, IT Manager, Lead Developer, Supervisor of Developers and many more - See more at: http:\/\/www.unlatched.com\/#sthash.8DiTkpKy.dpuf\",\"sameAs\":[\"http:\/\/www.andrewpallant.ca\",\"https:\/\/x.com\/LdnDeveloper\"],\"url\":\"http:\/\/andrewpallant.ca\/wordpress\/author\/ldndeveloper\/\"}]}<\/script>\r\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Dynamically Load MVC Partials Using jQuery - LDNDeveloper","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/andrewpallant.ca\/wordpress\/loading-mvc-partials-using-jquery\/","og_locale":"en_US","og_type":"article","og_title":"Dynamically Load MVC Partials Using jQuery - LDNDeveloper","og_description":"Normally I do my examples in C#, but lately I have noticed a lack of VB.NET examples. Therefore, this example is in VB.NET. I have searched long and hard to find a way to dynamically load MVC partials. I had tried to find a solution a few times, but quickly gave up. I figured there &hellip; Continue reading Dynamically Load MVC Partials Using jQuery","og_url":"http:\/\/andrewpallant.ca\/wordpress\/loading-mvc-partials-using-jquery\/","og_site_name":"LDNDeveloper","article_published_time":"2016-02-03T01:57:52+00:00","article_modified_time":"2020-01-10T16:23:34+00:00","author":"ldnDeveloper","twitter_card":"summary_large_image","twitter_creator":"@LdnDeveloper","twitter_site":"@LdnDeveloper","twitter_misc":{"Written by":"ldnDeveloper","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"http:\/\/andrewpallant.ca\/wordpress\/loading-mvc-partials-using-jquery\/#article","isPartOf":{"@id":"http:\/\/andrewpallant.ca\/wordpress\/loading-mvc-partials-using-jquery\/"},"author":{"name":"ldnDeveloper","@id":"https:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/f6f5bb1ac3e0c5a54a8b5ce35fd67b84"},"headline":"Dynamically Load MVC Partials Using jQuery","datePublished":"2016-02-03T01:57:52+00:00","dateModified":"2020-01-10T16:23:34+00:00","mainEntityOfPage":{"@id":"http:\/\/andrewpallant.ca\/wordpress\/loading-mvc-partials-using-jquery\/"},"wordCount":232,"publisher":{"@id":"https:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/f6f5bb1ac3e0c5a54a8b5ce35fd67b84"},"keywords":["DotNet","MVC"],"articleSection":["jQuery","Web"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"http:\/\/andrewpallant.ca\/wordpress\/loading-mvc-partials-using-jquery\/","url":"http:\/\/andrewpallant.ca\/wordpress\/loading-mvc-partials-using-jquery\/","name":"Dynamically Load MVC Partials Using jQuery - LDNDeveloper","isPartOf":{"@id":"https:\/\/andrewpallant.ca\/wordpress\/#website"},"datePublished":"2016-02-03T01:57:52+00:00","dateModified":"2020-01-10T16:23:34+00:00","breadcrumb":{"@id":"http:\/\/andrewpallant.ca\/wordpress\/loading-mvc-partials-using-jquery\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/andrewpallant.ca\/wordpress\/loading-mvc-partials-using-jquery\/"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/andrewpallant.ca\/wordpress\/loading-mvc-partials-using-jquery\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/andrewpallant.ca\/wordpress\/"},{"@type":"ListItem","position":2,"name":"Dynamically Load MVC Partials Using jQuery"}]},{"@type":"WebSite","@id":"https:\/\/andrewpallant.ca\/wordpress\/#website","url":"https:\/\/andrewpallant.ca\/wordpress\/","name":"LDNDeveloper","description":"Learning, Growing and Sharing.","publisher":{"@id":"https:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/f6f5bb1ac3e0c5a54a8b5ce35fd67b84"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/andrewpallant.ca\/wordpress\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/f6f5bb1ac3e0c5a54a8b5ce35fd67b84","name":"ldnDeveloper","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/image\/","url":"https:\/\/andrewpallant.ca\/wordpress\/wp-content\/uploads\/2017\/05\/cropped-AAEAAQAAAAAAAAXQAAAAJDQxMGRlMzFjLWM4ODctNDk1NC05M2EyLWE1NDNhNTRiZjVlYw-2.jpg","contentUrl":"https:\/\/andrewpallant.ca\/wordpress\/wp-content\/uploads\/2017\/05\/cropped-AAEAAQAAAAAAAAXQAAAAJDQxMGRlMzFjLWM4ODctNDk1NC05M2EyLWE1NDNhNTRiZjVlYw-2.jpg","width":512,"height":512,"caption":"ldnDeveloper"},"logo":{"@id":"https:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/image\/"},"description":"Andrew Pallant (@LdnDeveloper) has been a web, database and desktop developer for over 16 years. Andrew has worked on projects that ranged from factory automation to writing business applications. Most recently he has been heavily involved in various forms for ecommerce projects. Over the years Andrew has worn many hats: Project Manager, IT Manager, Lead Developer, Supervisor of Developers and many more - See more at: http:\/\/www.unlatched.com\/#sthash.8DiTkpKy.dpuf","sameAs":["http:\/\/www.andrewpallant.ca","https:\/\/x.com\/LdnDeveloper"],"url":"http:\/\/andrewpallant.ca\/wordpress\/author\/ldndeveloper\/"}]}},"_links":{"self":[{"href":"http:\/\/andrewpallant.ca\/wordpress\/wp-json\/wp\/v2\/posts\/1618"}],"collection":[{"href":"http:\/\/andrewpallant.ca\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/andrewpallant.ca\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/andrewpallant.ca\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/andrewpallant.ca\/wordpress\/wp-json\/wp\/v2\/comments?post=1618"}],"version-history":[{"count":4,"href":"http:\/\/andrewpallant.ca\/wordpress\/wp-json\/wp\/v2\/posts\/1618\/revisions"}],"predecessor-version":[{"id":1623,"href":"http:\/\/andrewpallant.ca\/wordpress\/wp-json\/wp\/v2\/posts\/1618\/revisions\/1623"}],"wp:attachment":[{"href":"http:\/\/andrewpallant.ca\/wordpress\/wp-json\/wp\/v2\/media?parent=1618"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/andrewpallant.ca\/wordpress\/wp-json\/wp\/v2\/categories?post=1618"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/andrewpallant.ca\/wordpress\/wp-json\/wp\/v2\/tags?post=1618"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}