1

I'm building a website using ASP.NET CORE with MVC, Razor and Bootstrap. I've started working with Typescript to deal with all my JavaScript, but now I'm stumbling upon an issue to which I can't find a solution. I think my approach is wrong, so I'd like to sketch my situation in a couple of requirements in the hope that someone can point me into the right direction:

  • In each Razor view I'd like to be able to use a Typescript class as sort of a 'ViewModel' to deal with all the JS for that specific view.
  • From within TypeScript I want to be able to import my own classes, such as my Form class to deal with form input and Ajax calls, and my Modal class to deal with showing Modals to the user.
  • In my Typescript classes I'd like to be able to use classes from other third parties such as Bootstrap Notify(@types/bootstrap-notify).

I've tried CommonJS and AMD with moduleResolution set to 'node', but this gives me an issue where I keep getting errors that 'define is not defined'. I've looked this up and this got me looking into Require.js. Made an attempt with this, but ended up giving me issues with not being able to do any imports in Typescript.

I see that my description might be rather vague, so the issue all comes down to this:

TL/DR: What is the recommended solution for working with Typescript with export/import and third party typings when using it in an ASP.NET Core Web project with Razor and Bootstrap in Visual Studio?

1 Answer 1

1

I've created a repository on GitHub with a solution to this problem. I've managed to implement ViewModels with Razor in ASP.NET Core by using Require.js: https://github.com/timthomassen/asp.net-core-razor-typescript-example

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.