├── img ├── mode1.png ├── mode2.png ├── AddView.png ├── ready_prod.png ├── MVC_Project.PNG ├── MVC_browser.PNG ├── vuejs_command.png ├── vuejs_running.png ├── vuetools_prod.png └── MVC_project_options.png ├── src ├── MVC_Vuejs │ ├── vuejs_src │ │ ├── babel.config.js │ │ ├── src │ │ │ ├── Feature1.vue │ │ │ ├── Feature2.vue │ │ │ ├── f1.js │ │ │ └── f2.js │ │ ├── .gitignore │ │ ├── README.md │ │ ├── public │ │ │ ├── featureTest1.html │ │ │ └── featureTest2.html │ │ ├── vue.config.js │ │ └── package.json │ ├── Global.asax │ ├── Controllers │ │ └── HomeController.cs │ ├── Global.asax.cs │ ├── packages.config │ ├── vuejs │ │ ├── featureTest1.html │ │ ├── featureTest2.html │ │ ├── index.html │ │ └── index2.html │ ├── App_Start │ │ └── RouteConfig.cs │ ├── Views │ │ ├── Home │ │ │ └── Index.cshtml │ │ └── web.config │ ├── Web.Debug.config │ ├── Web.Release.config │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Web.config │ └── MVC_Vuejs.csproj ├── readme_FIRST!.md ├── MVC_Vuejs.sln ├── .gitattributes └── .gitignore └── README.md /img/mode1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunsande/Vue.js-ASP.NET-MVC-intergration/HEAD/img/mode1.png -------------------------------------------------------------------------------- /img/mode2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunsande/Vue.js-ASP.NET-MVC-intergration/HEAD/img/mode2.png -------------------------------------------------------------------------------- /img/AddView.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunsande/Vue.js-ASP.NET-MVC-intergration/HEAD/img/AddView.png -------------------------------------------------------------------------------- /img/ready_prod.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunsande/Vue.js-ASP.NET-MVC-intergration/HEAD/img/ready_prod.png -------------------------------------------------------------------------------- /src/MVC_Vuejs/vuejs_src/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | '@vue/app' 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /img/MVC_Project.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunsande/Vue.js-ASP.NET-MVC-intergration/HEAD/img/MVC_Project.PNG -------------------------------------------------------------------------------- /img/MVC_browser.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunsande/Vue.js-ASP.NET-MVC-intergration/HEAD/img/MVC_browser.PNG -------------------------------------------------------------------------------- /img/vuejs_command.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunsande/Vue.js-ASP.NET-MVC-intergration/HEAD/img/vuejs_command.png -------------------------------------------------------------------------------- /img/vuejs_running.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunsande/Vue.js-ASP.NET-MVC-intergration/HEAD/img/vuejs_running.png -------------------------------------------------------------------------------- /img/vuetools_prod.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunsande/Vue.js-ASP.NET-MVC-intergration/HEAD/img/vuetools_prod.png -------------------------------------------------------------------------------- /src/MVC_Vuejs/Global.asax: -------------------------------------------------------------------------------- 1 | <%@ Application Codebehind="Global.asax.cs" Inherits="MVC_Vuejs.MvcApplication" Language="C#" %> 2 | -------------------------------------------------------------------------------- /img/MVC_project_options.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunsande/Vue.js-ASP.NET-MVC-intergration/HEAD/img/MVC_project_options.png -------------------------------------------------------------------------------- /src/readme_FIRST!.md: -------------------------------------------------------------------------------- 1 | If you want to use the source code do not forget to run the 2 | 3 | ``` 4 | npm i 5 | ``` 6 | 7 | inside the `vuejs_src` folder to get the `node_modules`. 8 | -------------------------------------------------------------------------------- /src/MVC_Vuejs/vuejs_src/src/Feature1.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 9 | 10 | -------------------------------------------------------------------------------- /src/MVC_Vuejs/vuejs_src/src/Feature2.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 9 | 10 | -------------------------------------------------------------------------------- /src/MVC_Vuejs/vuejs_src/src/f1.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import F1 from './Feature1.vue' 3 | 4 | Vue.config.productionTip = false 5 | 6 | new Vue({ 7 | render: h => h(F1), 8 | }).$mount('#f1App') 9 | -------------------------------------------------------------------------------- /src/MVC_Vuejs/vuejs_src/src/f2.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import F1 from './Feature2.vue' 3 | 4 | Vue.config.productionTip = false 5 | 6 | new Vue({ 7 | render: h => h(F1), 8 | }).$mount('#f2App') 9 | -------------------------------------------------------------------------------- /src/MVC_Vuejs/vuejs_src/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /dist 4 | 5 | # local env files 6 | .env.local 7 | .env.*.local 8 | 9 | # Log files 10 | npm-debug.log* 11 | yarn-debug.log* 12 | yarn-error.log* 13 | 14 | # Editor directories and files 15 | .idea 16 | .vscode 17 | *.suo 18 | *.ntvs* 19 | *.njsproj 20 | *.sln 21 | *.sw? 22 | -------------------------------------------------------------------------------- /src/MVC_Vuejs/Controllers/HomeController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Mvc; 6 | 7 | namespace MVC_Vuejs.Controllers 8 | { 9 | public class HomeController : Controller 10 | { 11 | // GET: Home 12 | public ActionResult Index() 13 | { 14 | return View(); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /src/MVC_Vuejs/Global.asax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Mvc; 6 | using System.Web.Routing; 7 | 8 | namespace MVC_Vuejs 9 | { 10 | public class MvcApplication : System.Web.HttpApplication 11 | { 12 | protected void Application_Start() 13 | { 14 | AreaRegistration.RegisterAllAreas(); 15 | RouteConfig.RegisterRoutes(RouteTable.Routes); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/MVC_Vuejs/vuejs_src/README.md: -------------------------------------------------------------------------------- 1 | # vuejs_src 2 | 3 | ## Project setup 4 | ``` 5 | npm install 6 | ``` 7 | 8 | ### Compiles and hot-reloads for development 9 | ``` 10 | npm run serve 11 | ``` 12 | 13 | ### Compiles and minifies for production 14 | ``` 15 | npm run build 16 | ``` 17 | 18 | ### Run your tests 19 | ``` 20 | npm run test 21 | ``` 22 | 23 | ### Lints and fixes files 24 | ``` 25 | npm run lint 26 | ``` 27 | 28 | ### Customize configuration 29 | See [Configuration Reference](https://cli.vuejs.org/config/). 30 | -------------------------------------------------------------------------------- /src/MVC_Vuejs/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/MVC_Vuejs/vuejs/featureTest1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Test Feature1 8 | 9 | 10 | 13 |
14 | 15 | -------------------------------------------------------------------------------- /src/MVC_Vuejs/vuejs/featureTest2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Test Feature2 8 | 9 | 10 | 13 |
14 | 15 | -------------------------------------------------------------------------------- /src/MVC_Vuejs/vuejs_src/public/featureTest1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Test Feature1 8 | 9 | 10 | 13 |
14 | 15 | -------------------------------------------------------------------------------- /src/MVC_Vuejs/vuejs_src/public/featureTest2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Test Feature2 8 | 9 | 10 | 13 |
14 | 15 | -------------------------------------------------------------------------------- /src/MVC_Vuejs/vuejs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Test Feature1 8 | 9 | 10 | 13 |
14 | 15 | -------------------------------------------------------------------------------- /src/MVC_Vuejs/vuejs/index2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Test Feature2 8 | 9 | 10 | 13 |
14 | 15 | -------------------------------------------------------------------------------- /src/MVC_Vuejs/App_Start/RouteConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Mvc; 6 | using System.Web.Routing; 7 | 8 | namespace MVC_Vuejs 9 | { 10 | public class RouteConfig 11 | { 12 | public static void RegisterRoutes(RouteCollection routes) 13 | { 14 | routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 15 | 16 | routes.MapRoute( 17 | name: "Default", 18 | url: "{controller}/{action}/{id}", 19 | defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } 20 | ); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/MVC_Vuejs/vuejs_src/vue.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | filenameHashing: false, 3 | productionSourceMap: false, 4 | outputDir: '../vuejs/', 5 | configureWebpack: { 6 | devtool: 'source-map', 7 | output: { 8 | filename: '[name].js' 9 | } 10 | }, 11 | pages: { 12 | feature1: { 13 | entry: 'src/f1.js', 14 | template: 'public/featureTest1.html', 15 | filename: 'index.html', 16 | title: 'Feature 1', 17 | chunks: ['chunk-vendors', 'chunk-common', 'feature1'] 18 | }, 19 | feature2: { 20 | entry: 'src/f2.js', 21 | template: 'public/featureTest2.html', 22 | filename: 'index2.html', 23 | title: 'Feature 2', 24 | chunks: ['chunk-vendors', 'chunk-common', 'feature2'] 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /src/MVC_Vuejs/Views/Home/Index.cshtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | ASP.NET MVC and Vue.js Integration 7 | 8 | 9 | 10 | @**@ 11 | 12 | 13 |

ASP.NET MVC and Vue.js Integration

14 | 15 | 16 | 17 |
18 |
19 | 20 | @**@ 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/MVC_Vuejs.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.572 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MVC_Vuejs", "MVC_Vuejs\MVC_Vuejs.csproj", "{932C80AA-0A42-4E3C-BD67-522D604CC9F4}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {932C80AA-0A42-4E3C-BD67-522D604CC9F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {932C80AA-0A42-4E3C-BD67-522D604CC9F4}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {932C80AA-0A42-4E3C-BD67-522D604CC9F4}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {932C80AA-0A42-4E3C-BD67-522D604CC9F4}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {BF99994F-6515-4C1A-BA9B-99368AFCC1F5} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /src/MVC_Vuejs/vuejs_src/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vuejs_src", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "serve": "vue-cli-service serve", 7 | "build": "vue-cli-service build", 8 | "build:dev": "vue-cli-service build src/f1.js src/f2.js --mode development", 9 | "lint": "vue-cli-service lint" 10 | }, 11 | "dependencies": { 12 | "core-js": "^2.6.5", 13 | "vue": "^2.6.10" 14 | }, 15 | "devDependencies": { 16 | "@vue/cli-plugin-babel": "^3.7.0", 17 | "@vue/cli-plugin-eslint": "^3.7.0", 18 | "@vue/cli-service": "^3.7.0", 19 | "babel-eslint": "^10.0.1", 20 | "eslint": "^5.16.0", 21 | "eslint-plugin-vue": "^5.0.0", 22 | "vue-template-compiler": "^2.5.21" 23 | }, 24 | "eslintConfig": { 25 | "root": true, 26 | "env": { 27 | "node": true 28 | }, 29 | "extends": [ 30 | "plugin:vue/essential", 31 | "eslint:recommended" 32 | ], 33 | "rules": {}, 34 | "parserOptions": { 35 | "parser": "babel-eslint" 36 | } 37 | }, 38 | "postcss": { 39 | "plugins": { 40 | "autoprefixer": {} 41 | } 42 | }, 43 | "browserslist": [ 44 | "> 1%", 45 | "last 2 versions" 46 | ] 47 | } 48 | -------------------------------------------------------------------------------- /src/MVC_Vuejs/Web.Debug.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 29 | 30 | -------------------------------------------------------------------------------- /src/MVC_Vuejs/Web.Release.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | 30 | 31 | -------------------------------------------------------------------------------- /src/MVC_Vuejs/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("MVC_Vuejs")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("MVC_Vuejs")] 13 | [assembly: AssemblyCopyright("Copyright © 2019")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("932c80aa-0a42-4e3c-bd67-522d604cc9f4")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Revision and Build Numbers 33 | // by using the '*' as shown below: 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /src/MVC_Vuejs/Views/web.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |
7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /src/MVC_Vuejs/Web.config: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 38 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /src/.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /src/.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | project.fragment.lock.json 46 | artifacts/ 47 | 48 | *_i.c 49 | *_p.c 50 | *_i.h 51 | *.ilk 52 | *.meta 53 | *.obj 54 | *.pch 55 | *.pdb 56 | *.pgc 57 | *.pgd 58 | *.rsp 59 | *.sbr 60 | *.tlb 61 | *.tli 62 | *.tlh 63 | *.tmp 64 | *.tmp_proj 65 | *.log 66 | *.vspscc 67 | *.vssscc 68 | .builds 69 | *.pidb 70 | *.svclog 71 | *.scc 72 | 73 | # Chutzpah Test files 74 | _Chutzpah* 75 | 76 | # Visual C++ cache files 77 | ipch/ 78 | *.aps 79 | *.ncb 80 | *.opendb 81 | *.opensdf 82 | *.sdf 83 | *.cachefile 84 | *.VC.db 85 | *.VC.VC.opendb 86 | 87 | # Visual Studio profiler 88 | *.psess 89 | *.vsp 90 | *.vspx 91 | *.sap 92 | 93 | # TFS 2012 Local Workspace 94 | $tf/ 95 | 96 | # Guidance Automation Toolkit 97 | *.gpState 98 | 99 | # ReSharper is a .NET coding add-in 100 | _ReSharper*/ 101 | *.[Rr]e[Ss]harper 102 | *.DotSettings.user 103 | 104 | # JustCode is a .NET coding add-in 105 | .JustCode 106 | 107 | # TeamCity is a build add-in 108 | _TeamCity* 109 | 110 | # DotCover is a Code Coverage Tool 111 | *.dotCover 112 | 113 | # NCrunch 114 | _NCrunch_* 115 | .*crunch*.local.xml 116 | nCrunchTemp_* 117 | 118 | # MightyMoose 119 | *.mm.* 120 | AutoTest.Net/ 121 | 122 | # Web workbench (sass) 123 | .sass-cache/ 124 | 125 | # Installshield output folder 126 | [Ee]xpress/ 127 | 128 | # DocProject is a documentation generator add-in 129 | DocProject/buildhelp/ 130 | DocProject/Help/*.HxT 131 | DocProject/Help/*.HxC 132 | DocProject/Help/*.hhc 133 | DocProject/Help/*.hhk 134 | DocProject/Help/*.hhp 135 | DocProject/Help/Html2 136 | DocProject/Help/html 137 | 138 | # Click-Once directory 139 | publish/ 140 | 141 | # Publish Web Output 142 | *.[Pp]ublish.xml 143 | *.azurePubxml 144 | # TODO: Comment the next line if you want to checkin your web deploy settings 145 | # but database connection strings (with potential passwords) will be unencrypted 146 | #*.pubxml 147 | *.publishproj 148 | 149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 150 | # checkin your Azure Web App publish settings, but sensitive information contained 151 | # in these scripts will be unencrypted 152 | PublishScripts/ 153 | 154 | # NuGet Packages 155 | *.nupkg 156 | # The packages folder can be ignored because of Package Restore 157 | **/packages/* 158 | # except build/, which is used as an MSBuild target. 159 | !**/packages/build/ 160 | # Uncomment if necessary however generally it will be regenerated when needed 161 | #!**/packages/repositories.config 162 | # NuGet v3's project.json files produces more ignoreable files 163 | *.nuget.props 164 | *.nuget.targets 165 | 166 | # Microsoft Azure Build Output 167 | csx/ 168 | *.build.csdef 169 | 170 | # Microsoft Azure Emulator 171 | ecf/ 172 | rcf/ 173 | 174 | # Windows Store app package directories and files 175 | AppPackages/ 176 | BundleArtifacts/ 177 | Package.StoreAssociation.xml 178 | _pkginfo.txt 179 | 180 | # Visual Studio cache files 181 | # files ending in .cache can be ignored 182 | *.[Cc]ache 183 | # but keep track of directories ending in .cache 184 | !*.[Cc]ache/ 185 | 186 | # Others 187 | ClientBin/ 188 | ~$* 189 | *~ 190 | *.dbmdl 191 | *.dbproj.schemaview 192 | *.jfm 193 | *.pfx 194 | *.publishsettings 195 | node_modules/ 196 | orleans.codegen.cs 197 | 198 | # Since there are multiple workflows, uncomment next line to ignore bower_components 199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 200 | #bower_components/ 201 | 202 | # RIA/Silverlight projects 203 | Generated_Code/ 204 | 205 | # Backup & report files from converting an old project file 206 | # to a newer Visual Studio version. Backup files are not needed, 207 | # because we have git ;-) 208 | _UpgradeReport_Files/ 209 | Backup*/ 210 | UpgradeLog*.XML 211 | UpgradeLog*.htm 212 | 213 | # SQL Server files 214 | *.mdf 215 | *.ldf 216 | 217 | # Business Intelligence projects 218 | *.rdl.data 219 | *.bim.layout 220 | *.bim_*.settings 221 | 222 | # Microsoft Fakes 223 | FakesAssemblies/ 224 | 225 | # GhostDoc plugin setting file 226 | *.GhostDoc.xml 227 | 228 | # Node.js Tools for Visual Studio 229 | .ntvs_analysis.dat 230 | 231 | # Visual Studio 6 build log 232 | *.plg 233 | 234 | # Visual Studio 6 workspace options file 235 | *.opt 236 | 237 | # Visual Studio LightSwitch build output 238 | **/*.HTMLClient/GeneratedArtifacts 239 | **/*.DesktopClient/GeneratedArtifacts 240 | **/*.DesktopClient/ModelManifest.xml 241 | **/*.Server/GeneratedArtifacts 242 | **/*.Server/ModelManifest.xml 243 | _Pvt_Extensions 244 | 245 | # Paket dependency manager 246 | .paket/paket.exe 247 | paket-files/ 248 | 249 | # FAKE - F# Make 250 | .fake/ 251 | 252 | # JetBrains Rider 253 | .idea/ 254 | *.sln.iml 255 | 256 | # CodeRush 257 | .cr/ 258 | 259 | # Python Tools for Visual Studio (PTVS) 260 | __pycache__/ 261 | *.pyc -------------------------------------------------------------------------------- /src/MVC_Vuejs/MVC_Vuejs.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | 8 | 9 | 2.0 10 | {932C80AA-0A42-4E3C-BD67-522D604CC9F4} 11 | {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} 12 | Library 13 | Properties 14 | MVC_Vuejs 15 | MVC_Vuejs 16 | v4.7 17 | true 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | true 29 | full 30 | false 31 | bin\ 32 | DEBUG;TRACE 33 | prompt 34 | 4 35 | 36 | 37 | true 38 | pdbonly 39 | true 40 | bin\ 41 | TRACE 42 | prompt 43 | 4 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | ..\packages\Microsoft.AspNet.Razor.3.2.4\lib\net45\System.Web.Razor.dll 67 | 68 | 69 | ..\packages\Microsoft.AspNet.Webpages.3.2.4\lib\net45\System.Web.Webpages.dll 70 | 71 | 72 | ..\packages\Microsoft.AspNet.Webpages.3.2.4\lib\net45\System.Web.Webpages.Deployment.dll 73 | 74 | 75 | ..\packages\Microsoft.AspNet.Webpages.3.2.4\lib\net45\System.Web.Webpages.Razor.dll 76 | 77 | 78 | ..\packages\Microsoft.AspNet.Webpages.3.2.4\lib\net45\System.Web.Helpers.dll 79 | 80 | 81 | ..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll 82 | 83 | 84 | ..\packages\Microsoft.AspNet.Mvc.5.2.4\lib\net45\System.Web.Mvc.dll 85 | 86 | 87 | ..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | Global.asax 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | Web.config 127 | 128 | 129 | Web.config 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 10.0 140 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | True 150 | True 151 | 64742 152 | / 153 | http://localhost:64742/ 154 | False 155 | False 156 | 157 | 158 | False 159 | 160 | 161 | 162 | 163 | 164 | 165 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 166 | 167 | 168 | 169 | 176 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Vue.js ASP.NET MVC Intergration 2 | How to integrate Vue.js into an existing ASP.Net MVC (not Core!) application (including development integration) 3 | 4 | ## Motivation 5 | 6 | Imagine one has an existing ASP.NET MVC project and wants to add some Vue.js components to it. One would like to keep the sources for the MVC and the Vue.js parts in a single solution and of course get the MVC application updated after some change in the Vue.js components occurs without manual copy of files between the solution folders. 7 | 8 | I will show a working solution for a simple straightforward setup (with almost no constraints). 9 | 10 | ## The Scenario 11 | 12 | We will start with an empty Asp.Net MVC Project. Then we will add only one trivial controller/action/view. Simultaneously we will setup a new Vue.js project and add it to the same Visual Studio solution. We will use the Vue.js CLI for that and we will build a multipage project (multiple entry points) - with two different pages (components). At the end we will integrate this 2 Vue.js components into the MVC view we created at the start. 13 | 14 | ## Software Versions 15 | 16 | At the time of writing I have Visual Studio Professional 2017/ Version 15.9.11 with .NET 4.7 and Vue.js CLI 3.7.0 and Vue.js 2.6.10. 17 | 18 | ## The ASP.NET MVC Project 19 | 20 | ![Selecting the ASP.NET MVC project template](img/MVC_Project.PNG) 21 | 22 | ![Template Options](img/MVC_project_options.png) 23 | 24 | Then we add `MVC 5 Controller - Empty` to the `Controllers` folder. We name it `HomeController` and leave the generated code as it is: 25 | ```csharp 26 | using System; 27 | using System.Collections.Generic; 28 | using System.Linq; 29 | using System.Web; 30 | using System.Web.Mvc; 31 | 32 | namespace MVC_Vuejs.Controllers 33 | { 34 | public class HomeController : Controller 35 | { 36 | // GET: Home 37 | public ActionResult Index() 38 | { 39 | return View(); 40 | } 41 | } 42 | } 43 | ``` 44 | 45 | The reason behind the name `HomeController` is that this is the name of the `Default` route in the `RouteConfig.cs`. So in this way the `Index` action will be automatically executed when the website is opened in the browser without further configuration. 46 | 47 | Further we define the view for the `Index` action. Just right-click inside the `Index()` method and select `Add View ...`: 48 | 49 | ![Add View ...](img/AddView.png) 50 | 51 | We will keep the view simple: 52 | 53 | ```razor 54 | 55 | 56 | 57 | 58 | 59 | ASP.NET MVC and Vue.js Integration 60 | 61 | 62 |

ASP.NET MVC and Vue.js Integration

63 | 64 | 65 | ``` 66 | 67 | And so we are ready on the ASP.NET MVC part: 68 | 69 | ![MVC in the browser](img/MVC_browser.PNG) 70 | 71 | ## Adding the Vue.js Project 72 | 73 | Here I assume you have `Vue.js` and `Vue.js CLI` already installed. 74 | 75 | Open the command line and navigate to the `<>` folder (... `MVC_Vuejs/MVC_Vuejs`). We would like to have the Vue.js project inside it. It's name would be `vuejs_src`. So we create the Vue.js project there using the Vue.js CLI: 76 | 77 | ``` 78 | vue create vuejs_src 79 | ``` 80 | ![Command propmt](img/vuejs_command.png) 81 | 82 | I would select the defaults here, but you may configure the Vue.js project as you need it and then: 83 | - run on the command line `cd vuejs_src` 84 | - run `npm run serve` 85 | - the result should be something like: ![MVC in the browser](img/vuejs_running.png) 86 | 87 | Now if you navigate to `http://localhost:8080/` you should be able to see the Vue.js default `Hello World` page. 88 | 89 | Good to notice is that the Vue.js project comes with all kinds of extras like `.gitignore` file. So it is ready to be included in the Visual Studio solution. There you should click on the `Show All Files` button (in the toolbar on the `Solution Explorer`). 90 | 91 | > **WARNING**: When adding the vuejs_src folder to the project DO NOT RIGHT-CLICK on the `vuejs_src` folder -> `Include In Project`! - there is a bug ot something and Visual Studio freezes. Maybe because of the size of the `node_modules` folder. 92 | 93 | We do not need to include the `node_modules` folder into the solution anyways, so just right-click any file or subfolder in `vuejs_src` other than `node_modules` and select `Include In Project`. (at the time of writing they are only 7 so it is not a big deal) 94 | 95 | So now we have the Vue.js project integrated into our ASP.NET MVC solution. Next we create some Vuejs components there and use them from the ASP.NET MVC view we created earlier. 96 | 97 | ## Create the Vuejs Components and Configure the Vuejs Project 98 | 99 | > When developing Vue.js projects I prefer to use Visual Studio Code (instead of Visual Studio alone). There is no problem to do so in the workflow described here. In your file explorer you just right-click on the vuejs_src folder and select `Open with Code`. From then on you can work with both editors. Normally I work in Visual Studio for ASP.NET MVC controllers/views and C# code and in Visual Studio Code for Vue.js/Javascript code. 100 | 101 | ### Workflow Description (what exactly are we trying to achieve?) 102 | 103 | So imagine now we have an existing ASP.NET MVC project and we would like to add some nice new Vue.js components into it. We will develop these new components inside the `vuejs_src` project and put them ready for use to the ASP.NET MVC project. 104 | 105 | So here particularly we will create two extremely simple Vue.js components named `Feature1` and `Feature2`. We will configure the Vue.js project to build multiple components (`*.js` files) to a dedicated solution `vuejs` folder. From there on the ASP.NET MVC view files (or any html files from the solution) will be able to reference and use these Vue.js components. 106 | 107 | > As you surely know Vue.js has development and production mode. We would like to keep using these and furthermore we would like to be able to build development versions of our Vue.js components so we can use the Vue.js developer tools in the browser while we are running the components in the ASP.NET MVC views. So we have 3 modes: 108 | > 1) Vue.js development mode (this is the Vue.js CLI local development server with hot reload) - here we do not use the ASP.NET MVC at all! 109 | > 2) Vue.js development components integrated into the ASP.NET MVC views 110 | > 3) Vue.js components in production mode integrated into the ASP.NET MVC views 111 | 112 | ### Creating the Example Feature1 and Feature2 Vue.js Components 113 | 114 | These will be trivial components just showing a string. In the folder `vuejs_src/src` we create `Feature1.vue`: 115 | ```vue.js 116 | // vuejs_src/src/Feature1.vue 117 | 122 | 123 | 125 | 126 | 128 | ``` 129 | 130 | And similarly the `Feature2.vue`. 131 | 132 | After that we create 2 Javascript files which load the Feature1.vue and Feature2.vue. In the folder `vuejs_src/src` we create `f1.js`: 133 | ```javascript 134 | // vuejs_src/src/f1.js 135 | import Vue from 'vue' 136 | import F1 from './Feature1.vue' 137 | 138 | Vue.config.productionTip = false 139 | 140 | new Vue({ 141 | render: h => h(F1), 142 | }).$mount('#f1App') 143 | ``` 144 | 145 | And similarly the `f2.js` (notice `f1 -> f2` and `#f1App -> #f2App`). 146 | 147 | ### Clear the Vue.js Project from the Default Files 148 | 149 | In order to keep the example as simple as possible we may clear the default files created from Vue.js CLI template. 150 | These are `main.js`, `App.vue`, the whole content of the `components`, `assets` and `public` folders. 151 | 152 | ### Setting up Mode 1 (Vue.js Development Mode with the Live Server) 153 | 154 | We have just deleted one important file - the `public/index.html`. Vue.js uses it as template wenn building the project. So let's create templates that suit our needs: 155 | 156 | ```html 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | Test Feature1 165 | 166 | 167 | 170 |
171 | 172 | 173 | ``` 174 | 175 | Similarly we create `featureTest2.html`. Note that `f1App`and `f2App` correspond to the mounting points of the `Feature1` and `Feature2` components. 176 | 177 | We changed the name of the default template from `index.html` to `featureTest[1/2].html` so now we have to tell to Vue.js to use the new templates. For that we need configuration file - we create `vuejs_src/vue.config.js`: 178 | 179 | ```javascript 180 | //vuejs_src/vue.config.js 181 | module.exports = { 182 | pages: { 183 | feature1: { 184 | entry: 'src/f1.js', 185 | template: 'public/featureTest1.html', 186 | filename: 'index.html', 187 | title: 'Feature 1', 188 | chunks: ['chunk-vendors', 'chunk-common', 'feature1'] 189 | }, 190 | feature2: { 191 | entry: 'src/f2.js', 192 | template: 'public/featureTest2.html', 193 | filename: 'index2.html', 194 | title: 'Feature 2', 195 | chunks: ['chunk-vendors', 'chunk-common', 'feature2'] 196 | } 197 | } 198 | } 199 | ``` 200 | 201 | So now if we run `npm run serve` and start web browser we will see: 202 | 203 | ![Mode 1](img/mode1.png) 204 | 205 | Loading `http://localhost:8080/index1.html` gives the same result. If we want to check the `Feature2` component we load `http://localhost:8080/index2.html`. 206 | 207 | You can manipulate the `filename` options in the `vue.config.js` to get the `Feature2` component loaded as default (`index.html`) or whatever other way you may want. 208 | 209 | ### Setting up Mode 3 (or Integrate the Production Versions of Feature1 and Feature2 in ASP.NET MVC View) 210 | 211 | First we have to add some options to the `vue.config.js`: 212 | ```javascript 213 | module.exports = { 214 | filenameHashing: false, 215 | productionSourceMap: false, 216 | outputDir: '../vuejs/', 217 | configureWebpack: { 218 | devtool: 'source-map', 219 | output: { 220 | filename: '[name].js' 221 | } 222 | }, 223 | pages: { 224 | hanakoFeature1: { 225 | entry: 'src/hf1.js', 226 | template: 'public/hanako_feature.html', 227 | filename: 'index1.html', 228 | title: 'Hanako Feature 1', 229 | chunks: ['chunk-vendors', 'chunk-common', 'hanakoFeature1'] 230 | }, 231 | hanakoFeature2: { 232 | entry: 'src/hf2.js', 233 | template: 'public/hanako_feature.html', 234 | filename: 'index.html', 235 | title: 'Hanako Feature 2', 236 | chunks: ['chunk-vendors', 'chunk-common', 'hanakoFeature2'] 237 | } 238 | } 239 | } 240 | ``` 241 | **Notes:** 242 | 243 | - `filenameHashing` - currently Vue.js CLI cannot use the `filenameHashing` feature when the template is not the `index.html`. On the other hand we want all things running automatically when integrating into an ASP.NET MVC view. If the hash changes on every `vuejs_src` project build, one has to change the `src` parameter in the view on every `vuejs_src` build. At the moment I do not know if it is possible in Vue.js to use constant hashes and how to use hashes without the `index.html` template. This would be a point for improvement. 244 | 245 | - `outputDir` - this is the dedicated folder where the ready to use `Feature1` and `Feature2` components will be placed after the `vuejs_src` project build. After a successful build we can include this folder to the solution and also to the source control system. 246 | 247 | If you do not specify the `outputDir` you will get everything in the `vuejs_src/dist` folder by default 248 | 249 | So now let's build the components: 250 | ``` 251 | npm run build 252 | ``` 253 | 254 | If you go to the `../vuejs/` folder you will find `feature1.js`, `feature2.js` and the `*.html` files generated from the templates. Currently I do not know how/if one can suppress their creation. There is one more file created `js/chunk-vendors.js`. I do not know how to configure the Vue.js CLI to put this file along with the others and not under the `js/` folder. Anyway it is not really big limitation. 255 | 256 | Next we go to the ASP.NET MVC view file we created earlier and we add to it: 257 | ```razor 258 | 259 | 260 | 261 | 262 | 263 | ASP.NET MVC and Vue.js Integration 264 | 265 | 266 | 267 | 268 | 269 | 270 |

ASP.NET MVC and Vue.js Integration

271 | 272 | 273 | 274 |
275 |
276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | ``` 284 | 285 | Now we can start the ASP.NET MVC application we created and voilà: 286 | 287 | ![Production ready](img/ready_prod.png) 288 | 289 | Note that if you want to debug the application in the browser using the Vue.js developer tools you won't be able to do so, because we builded the components in production mode. 290 | 291 | ![Production mode debug](img/vuetools_prod.png) 292 | 293 | So let's enable that in the next step. 294 | 295 | ### Setting up Mode 2 (or Integrate the Developer Versions of Feature1 and Feature2 in ASP.NET MVC View) 296 | 297 | We only have to create one additional build step to do so. To acheive it we add new `build:dev` command to our `vuejs_src/package.json`: 298 | 299 | ```json 300 | { 301 | "name": "vuejs_src", 302 | "version": "0.1.0", 303 | "private": true, 304 | "scripts": { 305 | "serve": "vue-cli-service serve", 306 | "build": "vue-cli-service build", 307 | --> "build:dev": "vue-cli-service build src/f1.js src/f2.js --mode development", 308 | "lint": "vue-cli-service lint" 309 | }, 310 | "dependencies": { 311 | ... 312 | } 313 | 314 | ``` 315 | 316 | There is another small inconvenience here to fix. The result of this new command: 317 | ``` 318 | npm run build:dev 319 | ``` 320 | are only the `feature1.js` and `feature2.js` components (much bigger in size!). So we have to comment the lines in the ASP.NET MVC view file for the `chunk-vendors.js` - otherwise the browser will show `404 Not Found` error. But after that you only have to reaload the page (`Ctrl+F5`) and there it is - the Vue.js developer tools work now perfectly: 321 | 322 | ![Mode 2](img/mode2.png) 323 | 324 | --------------------------------------------------------------------------------