{"id":1,"date":"2015-07-14T22:21:28","date_gmt":"2015-07-14T22:21:28","guid":{"rendered":"http:\/\/pfool.com\/blog\/?p=1"},"modified":"2016-08-24T20:02:51","modified_gmt":"2016-08-24T20:02:51","slug":"ace-template-mvc-5","status":"publish","type":"post","link":"https:\/\/pfool.com\/blog\/2015\/07\/14\/ace-template-mvc-5\/","title":{"rendered":"Integrating a Bootstrap template into an MVC 5 Application"},"content":{"rendered":"<p>I purchased the <b>Ace Admin template<\/b> from <a href=\"https:\/\/wrapbootstrap.com\" target=\"_blank\">wrapbootstrap.com<\/a> and wanted to use it in an MVC 5 web application developed in Visual Studio. This article explains how I did that. Just for reference, the Ace Admin template is no longer available from wrapbootstrap but the process described here should be similar for any 3rd party Bootstrap template.<\/p>\n<hr>\n<p>The standard MVC 5 application template that is delivered with Visual Studio 2013 makes use of Bootstrap 3 to provide a responsive web application. The default installation of Bootstrap puts the CSS files in the <b>Content<\/b> folder and the javascript files in the <b>Scripts <\/b>folder.<\/p>\n<figure id=\"attachment_11\" aria-describedby=\"caption-attachment-11\" style=\"width: 267px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/pfool.com\/blog\/wp-content\/uploads\/2015\/05\/001.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-11\" src=\"http:\/\/pfool.com\/blog\/wp-content\/uploads\/2015\/05\/001.jpg\" alt=\"MVC 5 file layout\" width=\"267\" height=\"432\" srcset=\"https:\/\/pfool.com\/blog\/wp-content\/uploads\/2015\/05\/001.jpg 267w, https:\/\/pfool.com\/blog\/wp-content\/uploads\/2015\/05\/001-185x300.jpg 185w\" sizes=\"auto, (max-width: 267px) 100vw, 267px\" \/><\/a><figcaption id=\"caption-attachment-11\" class=\"wp-caption-text\">Visual Studio MVC 5 file layout<\/figcaption><\/figure>\n<p>As delivered, the Ace Admin template has a directory named <b>assets <\/b>which contains additional folders which contain the various resource files.<\/p>\n<figure id=\"attachment_12\" aria-describedby=\"caption-attachment-12\" style=\"width: 396px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/pfool.com\/blog\/wp-content\/uploads\/2015\/05\/002.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-12\" src=\"http:\/\/pfool.com\/blog\/wp-content\/uploads\/2015\/05\/002.jpg\" alt=\"Ace Admin file layout\" width=\"396\" height=\"345\" srcset=\"https:\/\/pfool.com\/blog\/wp-content\/uploads\/2015\/05\/002.jpg 396w, https:\/\/pfool.com\/blog\/wp-content\/uploads\/2015\/05\/002-300x261.jpg 300w\" sizes=\"auto, (max-width: 396px) 100vw, 396px\" \/><\/a><figcaption id=\"caption-attachment-12\" class=\"wp-caption-text\">Ace Admin file layout<\/figcaption><\/figure>\n<p>In order to integrate this into the VS 2013 MVC app, I created folders with those same names in Solution Explorer. I created the <b>js<\/b> directory under the <b>Scripts<\/b> folder in Solution Explorer and created all of the others (<b>avatars<\/b>, <b>css<\/b>, <b>font<\/b>, etc.) under the <b>Content<\/b> folder in Solution Explorer. By doing this, there will be no conflict of files with the same name between what is in the default MVC application and what is provided in the Ace Admin template files (such as <b>bootstrap.css<\/b> and <b>bootstrap.js<\/b>). By separating the files in this manner, it will make it easier to update either the Bootstrap package provided through NuGet within Visual Studio or any updates to the Ace Admin template. When creating Script bundles or Style bundles within the BundleConfig.cs file of the project, I set references to bootstrap.cs and bootstrap.js to point to the files that are in the VS NuGet package rather than the files in the Ace directories. By doing this, the project will use the latest Bootstrap version that has been installed via NuGet from within VS. The documentation for Ace Admin template states that it is compatible with Bootstrap 3.3.x. Version 1.3.3 of the Ace Admin template is delivered with files for Bootstrap 3.3.1. The latest version of Bootstrap available via NuGet is 3.3.4 at this point in time.<\/p>\n<figure id=\"attachment_13\" aria-describedby=\"caption-attachment-13\" style=\"width: 477px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/pfool.com\/blog\/wp-content\/uploads\/2015\/05\/003.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-13\" src=\"http:\/\/pfool.com\/blog\/wp-content\/uploads\/2015\/05\/003.jpg\" alt=\"Use Bootstrap files from NuGet package\" width=\"477\" height=\"455\" srcset=\"https:\/\/pfool.com\/blog\/wp-content\/uploads\/2015\/05\/003.jpg 477w, https:\/\/pfool.com\/blog\/wp-content\/uploads\/2015\/05\/003-300x286.jpg 300w\" sizes=\"auto, (max-width: 477px) 100vw, 477px\" \/><\/a><figcaption id=\"caption-attachment-13\" class=\"wp-caption-text\">Use Bootstrap files from NuGet package<\/figcaption><\/figure>\n<p>This all worked fine in Debug mode because the files were not actually being bundled or minified.<br \/>\nHere is the network traffic info (gotten from IE F12 Developer Tools):<\/p>\n<figure id=\"attachment_14\" aria-describedby=\"caption-attachment-14\" style=\"width: 857px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/pfool.com\/blog\/wp-content\/uploads\/2015\/05\/004.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-14\" src=\"http:\/\/pfool.com\/blog\/wp-content\/uploads\/2015\/05\/004.jpg\" alt=\"Network traffic\" width=\"857\" height=\"492\" srcset=\"https:\/\/pfool.com\/blog\/wp-content\/uploads\/2015\/05\/004.jpg 857w, https:\/\/pfool.com\/blog\/wp-content\/uploads\/2015\/05\/004-300x172.jpg 300w\" sizes=\"auto, (max-width: 857px) 100vw, 857px\" \/><\/a><figcaption id=\"caption-attachment-14\" class=\"wp-caption-text\">Network traffic<\/figcaption><\/figure>\n<p>I then forced bundling to occur by putting the following statement in the BundleConfig.cs (this could be done through the web.config as well):<\/p>\n<p>BundleTable.EnableOptimizations = true;<\/p>\n<p>Running the application, it looked awful. It looked like there wasn&#8217;t any CSS being applied to the page. Here&#8217;s how the network traffic looked:<\/p>\n<p><a href=\"http:\/\/pfool.com\/blog\/wp-content\/uploads\/2015\/05\/005.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-6\" src=\"http:\/\/pfool.com\/blog\/wp-content\/uploads\/2015\/05\/005.jpg\" alt=\"Initial bundled network traffic\" width=\"859\" height=\"291\" srcset=\"https:\/\/pfool.com\/blog\/wp-content\/uploads\/2015\/05\/005.jpg 859w, https:\/\/pfool.com\/blog\/wp-content\/uploads\/2015\/05\/005-300x102.jpg 300w\" sizes=\"auto, (max-width: 859px) 100vw, 859px\" \/><\/a><\/p>\n<p>The CSS files were not getting transferred which is why the web page looked so bad.<\/p>\n<p>After some research, I discovered that I could not use ~\/Content\/css as a virtual path for the bundle because I had an actual physical path that existed for that same location. So I tried changing the virtual bundle path to ~\/Content\/css2.<\/p>\n<p>Running the application, everything looked right again on the page so I was obviously getting the CSS files. However, looking at the network traffic showed another problem was occurring.<\/p>\n<p><a href=\"http:\/\/pfool.com\/blog\/wp-content\/uploads\/2015\/05\/006.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7\" src=\"http:\/\/pfool.com\/blog\/wp-content\/uploads\/2015\/05\/006.jpg\" alt=\"Files not found\" width=\"912\" height=\"294\" srcset=\"https:\/\/pfool.com\/blog\/wp-content\/uploads\/2015\/05\/006.jpg 912w, https:\/\/pfool.com\/blog\/wp-content\/uploads\/2015\/05\/006-300x97.jpg 300w\" sizes=\"auto, (max-width: 912px) 100vw, 912px\" \/><\/a><\/p>\n<p>Some of the font related files used in the Ace Admin template were not being found. The reason for this was that there was a relative path being specified in the @font-face definition in the CSS file. Changing the relative path in the CSS from ..\/fonts to ..\/Contents\/fonts would make it work when bundling was turned on. However, when bundling was turned off, once again the files would not be found. The real problem was that the virtual path for the bundle and the path for the CSS file were at different levels of the application directory structure. I was able to solve this issue by creating the virtual path of the bundle to be at the same relative position in the application directory structure as the CSS file.<\/p>\n<p><a href=\"http:\/\/pfool.com\/blog\/wp-content\/uploads\/2015\/05\/007.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8\" src=\"http:\/\/pfool.com\/blog\/wp-content\/uploads\/2015\/05\/007.jpg\" alt=\"Resolve path conflict\" width=\"438\" height=\"181\" srcset=\"https:\/\/pfool.com\/blog\/wp-content\/uploads\/2015\/05\/007.jpg 438w, https:\/\/pfool.com\/blog\/wp-content\/uploads\/2015\/05\/007-300x124.jpg 300w\" sizes=\"auto, (max-width: 438px) 100vw, 438px\" \/><\/a><\/p>\n<p>This works for both bundled and unbundled delivery of the CSS\/script files.<\/p>\n<p>For more info on bundling and minification see the following article:<br \/>\n<a href=\"http:\/\/www.asp.net\/mvc\/overview\/performance\/bundling-and-minification\"><br \/>\nhttp:\/\/www.asp.net\/mvc\/overview\/performance\/bundling-and-minification<\/a><\/p>\n<p>Hopefully, this gives you enough information to be on your way with integrating a Bootstrap theme into your own MVC 5 project in Visual Studio.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I purchased the Ace Admin template from wrapbootstrap.com and wanted to use it in an MVC 5 web application developed in Visual Studio. This article &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3],"class_list":["post-1","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-wrapbootstrap"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pfool.com\/blog\/wp-json\/wp\/v2\/posts\/1","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pfool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pfool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pfool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pfool.com\/blog\/wp-json\/wp\/v2\/comments?post=1"}],"version-history":[{"count":2,"href":"https:\/\/pfool.com\/blog\/wp-json\/wp\/v2\/posts\/1\/revisions"}],"predecessor-version":[{"id":44,"href":"https:\/\/pfool.com\/blog\/wp-json\/wp\/v2\/posts\/1\/revisions\/44"}],"wp:attachment":[{"href":"https:\/\/pfool.com\/blog\/wp-json\/wp\/v2\/media?parent=1"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pfool.com\/blog\/wp-json\/wp\/v2\/categories?post=1"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pfool.com\/blog\/wp-json\/wp\/v2\/tags?post=1"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}