search results:

    • Standard
    • React
    Pricing Learn Community
    • + D
    • Light
    • Dark
    • System
    logo TW Elements
    • Getting started
      • Quick start
      • Tutorials
      • Design system
      • Local installation
      • Optimization
      • Dark mode
      • Theming
      • Changelog
      • Migrating to v2
      • Internationalization guide
      • Class customization
      • Icons Integration
    • CommercialNew
      • Pricing
      • License
      • Installation
      • Git & repository
      • Premium Support
    • Integrations
      • Angular
      • ASP.NET
      • Django
      • Express
      • Laravel
      • Next
      • Nuxt
      • Qwik
      • React
      • Remix
      • Solid
      • Svelte
      • SvelteKit
      • Vue
    • Content & styles
      • Animations
      • Animations Extended
      • Colors
      • Dividers
      • Figures
      • Headings
      • Hover effects
      • Icons
      • Images
      • Mask
      • Shadows
      • Typography
    • Navigation
      • Breadcrumbs
      • Footer
      • Headers
      • Mega menu
      • Navbar
      • Offcanvas
      • Pagination
      • Pills
      • Scrollspy
      • Sidenav
      • Tabs
    • Components
      • Accordion
      • Alerts
      • Avatar
      • Badges
      • Button group
      • Buttons
      • Cards
      • Carousel
      • Chips
      • Collapse
      • Dropdown
      • Gallery
      • Jumbotron
      • Lightbox
      • Link
      • List group
      • Modal
      • Notifications
      • Paragraphs
      • Placeholders
      • Popconfirm
      • Popover
      • Progress
      • Rating
      • Scroll back to top button
      • Social buttons
      • Spinners
      • Stepper
      • Testimonials
      • Timeline
      • Toast
      • Tooltip
      • Video
      • Video carousel
    • Forms
      • Autocomplete
      • Checkbox
      • Datepicker
      • Datetimepicker
      • File input
      • Form templates
      • Input Group
      • Inputs
      • Login form
      • Multi range slider
      • Radio
      • Range
      • Registration form
      • Search
      • Select
      • Switch
      • Textarea
      • Timepicker
      • Validation
    • Data
      • Charts
      • Charts advanced
      • Datatables
      • Tables
    • Methods
      • Clipboard
      • Infinite scroll
      • Lazy loading
      • Loading management
      • Ripple
      • Scrollbar
      • Smooth scroll
      • Sticky
      • Touch
    • Design Blocks
      • Admin Charts
      • Admin Complex
      • Admin Forms
      • Admin Maps
      • Admin Navigation
      • Admin tables
      • Banners
      • Contact
      • Content
      • CTA
      • FAQ
      • Features
      • Headers
      • Hero / Intro sections
      • Logo clouds
      • Mega menu
      • News
      • Newsletter
      • Pricing
      • Projects
      • Stats
      • Stats admin
      • Team
      • Testimonials
    • Tools
      • Button generator
      • Card generator
      • Flexbox generator
      • Footer generator
      • Form builder
      • Grid generator
      • Icon generator
      • Instagram Filters generator
      • Logo generator
      • Table generator
      • Typography generator
    • Coming Soon
      • Angular
      • Builder
      • Templates
      • Vue
    • Resources
      • Playground
      • YouTube Channel
      • Private FB Group
      • Newsletter
      • UI Design course New
      • UI / UX tips

    TW Elements .NET core + ASP.NET core integration

    This article shows you how to integrate .NET core + ASP.NET core application with TW Elements. Free download, open source license.


    Prerequisites

    Before starting the project make sure to install the following utilities:

    • Node LTS (18.x.x or higher recommended)
    • .NET 8.0 SDK (this tutorial was created with .NET 6.0)
    • Code editor. We recommend VSCode

    Creating a new ASP.NET application

    Let's begin by setting up a brand-new ASP.NET application together. This way, we're all on the same page, and we can walk through each step together.

    Step 1

    Create a new app with use of dotnet and go to the newly created directory.

    • Terminal
            
                
        dotnet new webapp -o my-project
        cd my-project
        
            
        

    That's it for now! Let's install tw-elements.


    Installing and configuring Tailwind CSS and TW Elements

    Step 1

    File structure

    If you are using the .NET 8.0 SDK version, your project file structure should look like this (package.json and config files will be created in the next steps):

          
            my-project/
            ├── obj/
            ├── Pages/    
            │   ├── Shared/ 
            │   │   ├── ...
            │   │   └── _Layout.cshtml
            │   │   └── _Layout.cshtml.css
            │   ├── ...
            │   └── Index.cshtml
            ├── Properties/   
            ├── wwwroot/   
            │   ├── css/ 
            │   │   └── site.css
            │   ├── js/ 
            │   │   └── site.js
            │   ├── ...
            │   ├── package.json
            │   ├── postcss.config.js
            │   └── tailwind.config.js
            └── ...
          
        

    Now that we have analyzed what our project looks like let's install Tailwind CSS. We are going to install our packages inside the wwwroot directory.

    Note: If, after running npm install within the wwwroot directory, you find that there is no package.json file or node_modules directory, please run npm init and then retry this step.
    • Terminal
            
                
        npm install -D tailwindcss postcss autoprefixer
        npx tailwindcss init -p
        
            
        

    Step 2

    Add the paths to all of your template files in your tailwind.config.js file.

    • ./wwwroot/tailwind.config.js
            
                
        /** @type {import('tailwindcss').Config} */
        module.exports = {
          content: [
            "../Pages/**/*.cshtml",
            "./js/**/*.js",
            "./node_modules/tw-elements/js/**/*.js",
          ],
          darkMode: "class",
          plugins: [require("tw-elements/plugin.cjs")],
        };
        
            
        

    Step 3

    Replace the styles that were created via dotnet inside site.css file with Tailwind directives.

    • ./wwwroot/css/site.css
            
                
        @import url("https://fonts.googleapis.com/css?family=Roboto:300,400,500,700,900&display=swap");
        @tailwind base;
        
        @layer base {
          html {
            @apply text-surface;
            @apply bg-white;
          }
          html.dark {
            @apply text-neutral-50;
            @apply bg-body-dark;
          }
        }
        
        @tailwind components;
        @tailwind utilities;
        
        p {
          @apply leading-[1.6];
        }           
        
            
        

    Step 4

    Install TW Elements.

    • Terminal
            
                
        npm install tw-elements
        
            
        

    Step 5

    Start the Tailwind CLI build process. Run the CLI tool to scan your template files for classes and build your CSS. Links are related to the wwwroot directory so make sure you are in the right place.

    • terminal
            
                
        npx tailwindcss -i ./css/site.css -o ./css/output.css --watch
        
            
        

    You can also add this script to the package.json so that you can run it later again without worrying about input and output files.

    • ./wwwroot/package.json
            
                
        "scripts": {
          "build-tw": "npx tailwindcss -i ./css/site.css -o ./css/output.css --watch"
        },
        
            
        

    Step 6

    Now we have to add the styles and script to our _Layout.cshtml file. Navigate to Pages/Shared/_Layout.cshtml and add the following code inside the head tag.

    • ./Pages/Shared/_Layout.cshtml
            
                
        ...
        <head>
          ...
          <link
            rel="stylesheet"
            href="~/css/output.css"
            asp-append-version="true" />
          ...
        </head>
        ...
        
            
        

    And add the following code before the closing body tag.

    • ./Pages/Shared/_Layout.cshtml
            
                
        <body>
          ...
          <script
            type="module"
            src="~/node_modules/tw-elements/dist/js/tw-elements.umd.min.js"></script>
        </body>
        
            
        

    Optional: You can also remove the rest of the content inside the body tag. Leave only the @RenderBody() and script tags.

    Step 7

    Navigate the the ./Pages/Shared/_Layout.cshtml.css and remove styles that were added during creating the new ASP.NET app.

    Step 8

    Now we can start working on our TWE app. Add the TWE components you intend to use in your project for example into Index.cshtml file.

    • ./Pages/Index.cshtml
            
                
        @page
        @model IndexModel
        @{
            ViewData["Title"] = "TWE Integration";
        }
    
        <div class="mt-16 flex justify-center">
          <p class="text-lg">
            Hover the link to see the
            <a
              href="#"
              class="text-primary transition duration-150 ease-in-out hover:text-primary-600 focus:text-primary-600 active:text-primary-700 dark:text-primary-400 dark:hover:text-primary-500 dark:focus:text-primary-500 dark:active:text-primary-600"
              data-twe-toggle="tooltip"
              title="Hi! I'm tooltip"
              >tooltip</a
            >
          </p>
        </div>
        
            
        

    Step 9

    Run the local server. You're all set to dive into using TW Elements for your ASP.NET project. Have fun!

    • Terminal
            
                
        dotnet run
        
            
        

    Related resources

    Tutorials:

    introduction key concepts quick start mdb go and deploy create website about versions installation setup overview create landing page javascript tailwind css intellisense deploy repository

    Integrations :

    angular django laravel next nuxt react remix solid svelte sveltekit vue
    • Prerequisites
    • Creating a new ASP.NET application
    • Installing and configuring Tailwind CSS and TW Elements
    • Related resources
    Get useful tips & free resources directly to your inbox along with exclusive subscriber-only content.
    Join our mailing list now
    © 2024 Copyright: MDBootstrap.com

    Access restricted

    To view this section you must have an active PRO account

    Log in to your account or purchase an TWE subscription if you don't have one.

    Buy TWE PRO