0

I have a project built in ASP.NET Core MVC. Using the built in identity functionality. I would like to serve certain views using angular 4 and certain ones using Razor, depending on the functionality required and the migration. For example I have a schedule route and would like anything under /Schedule to be loaded using Angular, as a result loading the schedule.component.html.

I have attempted by installing Angular under a ClientApp folder under wwwroot. I have an index.html that loads the dependencies, this works however I am unsure of how to load the schedule component when using the schedule root.

Will appreciate any help thanks.

Index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Home</title>
<script src="ClientApp/node_modules/core-js/client/shim.min.js"></script>
<script src="ClientApp/node_modules/zone.js/dist/zone.js"></script>
<script src="ClientApp/node_modules/reflect-metadata/Reflect.js"></script>
<script src="ClientApp/node_modules/systemjs/dist/system.src.js"></script>
<script src="systemjs.config.js"></script>
<script>
    System.import('app')
        .then(
        function () { console.log('started application'); },
        function (err) { console.log('error starting application'); 
console.log(err); });
</script>
</head>
<app-root>Loading..</app-root>
<body>
</body>
</html>
5
  • Too avoid confusion in future please stop using the outdated term "MVC6". There is no such version anymore and it was only used for a firm time before the preview releases. The version numbering for ASP.NET Core was reset and started with 1.0 and at the time of the writing has reached the version 2.1. It's imply called "ASP.NET Core MVC" (up to 2.1) and "ASP.NET MVC" (up to version 5.2) for the old legacy framework. Reasons were that MVC6 suggested its an follow up of MVC5 which is not the case. ASP.NET Core is a complete rewrite and incompatible with ASP.NET Commented May 1, 2018 at 17:53
  • @Tseng Noted. Thanks, now that the question avoids confusion are you able to assist? Commented May 1, 2018 at 19:37
  • Can just provide an opinion, no answer though: Wouldn't recommend neither trying to serve the angular part yourself nor trying to mix angular with mvc views. Angular is for SPA (Single Page Application, means its loaded once and then everything else happens in browser which is in contrast to Razor views which are rendered on the server and each time a new request is required), otherwise your app will be reinitialized every time you switch between razor view route and angular route. Commented May 1, 2018 at 19:40
  • I'd recommend to stay with the default angular templates. Also upgrade to the latest tempaltes, see this answer for whats different as the new angular templates are based on angular cli in contrast to the old devwebpack based tempaltes. They come preconfigured with server-side rendering and more important with application bundling, where all the angular files are bundled into a single file for loading performance Commented May 1, 2018 at 19:43
  • Ok thanks, is it possible to serve a portion of the application in angular, for example, asp-core handles the login and redirects them to the home razor view, then they click a link, that takes them to the angular route (A different Project) and then this eventually redirects back, as an approach to start migrating certain sections of the webapp into angular? Commented May 1, 2018 at 20:04

0

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.