@manhng

Welcome to my blog!

Prepare ASP.NET Core Projects To Use TypeScript

November 16, 2020 22:04

Prepare ASP.NET Core Projects To Use TypeScript (edit)

Prepare ASP.NET Core projects to use TypeScript | BinaryIntellect Knowledge Base

  • Add folder TypeScript in wwwroot folder
  • Ctrl + Shift + A: Add a new TypeScript file named HelloWorld.ts in TypeScript folder
    function HelloWorld() {
        document.getElementById("msg")
       .innerHTML = "<h1>Hello World!</h1>";
    }
  • Then save the TypeScript file. As you save the file you will find that automatically Visual Studio compiles it to produce HelloWorld.js
  • Solution Explorer > Alt + Space > dotnet build
    • TypeScriptDemo -> C:\Users\Manh\source\repos\TypeScriptDemo\TypeScriptDemo\bin\Debug\netcoreapp3.1\TypeScriptDemo.dll
    • TypeScriptDemo -> C:\Users\Manh\source\repos\TypeScriptDemo\TypeScriptDemo\bin\Debug\netcoreapp3.1\TypeScriptDemo.Views.dll
  • Add code to run at document ready: Pure JavaScript equivalent of jQuery's $.ready() - how to call a function when the page/DOM is ready for it - Stack Overflow
  • View > Index.cshtml
    @{
        ViewData["Title"] = "Home Page";
    }
     
    <div class="text-center">
        <h1 class="display-4">Welcome</h1>
        <p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
        <div id="msg"></div>
        <script src="~/TypeScript/HelloWorld.js"></script>
        <script>
            // Self executing function here
            (function () {
                // your page initialization code here
                // the DOM will be available here
                HelloWorld();
            })();
        </script>
    </div>
  • Ctrl + Shift + A: Add a new TypeScript JSON Configuration file in the TypeScript folder named tsconfig.json
  • TypeScript compiler settings: The name of this file must be tsconfig.json and it contains TypeScript compiler settings
{
  "compilerOptions": {
    "noImplicitAny": false,
    "noEmitOnError": true,
    "removeComments": false,
    "sourceMap": true,
    "target": "es5",
    "outDir": "./Output"
  },
  "compileOnSave": true,
  "exclude": [
    "node_modules"
  ]
}
  • Make sure to add the Output folder in the ..\wwwroot\TypeScript\ folder
  • Change the Index.cshtml so that correct to the .js file in the above Output folder.
  • F5 to Run

ASP.NET Core - Upload files

Upload files in ASP.NET Core | Microsoft Docs

Asp.net Core file upload example uploading multiple files (webtrainingroom.com)

Handling multipart requests with JSON and file uploads in ASP.NET Core - Thomas Levesque's .NET Blog (JSON + UPLOAD FILE) (HAY HAY HAY)

Uploading and returning files in ASP.NET MVC (prideparrot.com) (Validate Upload File: FileTypesAttribute, FileSizeAttribute)

Web API File Upload, Single or Multiple files | Software Engineering (damienbod.com)

Quickstart: Azure Blob storage library v12 - .NET | Microsoft Docs

Custom Model Binding in ASP.NET Core | Microsoft Docs (HAY HAY HAY)

Windows Azure

Azure WebState - CodeProject (2013)

Database Transaction Management across AJAX Calls

Database Transaction Management across AJAX Calls - CodeProject

What's presented here is a workaround that is optimized as best as possible but relies on synchronization with regards to the use of the SqlConnection instance. Probably the simplest way to work around the issues is to not use these class at all and manage connection pooling outside of the context of a using new SqlConnection statement, as this closes the connection when the using exits and invalidates the transaction. 

16 Days: A TypeScript Application from Concept to Implementation - CodeProject

Categories

Recent posts