Why does Bootstrap under ASP.NET Core install Razo

2019-09-15 15:24发布

问题:

I've deployed a Core website generated by Yeoman (yo aspnet) and when asked what to put in as a GUI manager I had two choices - Bootstrap and Semantic. I went with Bootstrap and everything went well but...

When I checked out the contents, I realized that the difference between empty web application and web application/bootstrap is more than I expected. I got me a full blown MVC setup with views, controllers etc. And all the views are of course managed by Razor.

So my question is if it makes sense to skip Razor. If so, what's the alternative (goolearching gave me very little on this)?

I'm planning on going for Angular 2. Does it make sense to install Bootstrap at a later occasion? Or at all?

回答1:

If all you need is a static index.html in wwwroot, then you don't need it.

Must be something with yeoman installing the MVC by default, bootstrap by default (the NPM/Bower dependency) is just a bunch of javascript & css files.

If you need Controllers (for WebAPI/REST service calls, but not razor), you can use "Microsoft.AspNetCore.Mvc.Core": "1.0.1" dependency rather than "Microsoft.AspNetCore.Mvc": "1.0.1". The later package also pulls all dependencies required for MVC including Razor. When using the Mvc.Core package you need to register it with AddMvcCore() in ConfigureServiuces() rather than AddMvc().

If you need neither one (because your WebAPI is in a different project), then just remove the dependency. But you need UseStaticFiles/UseDefaultFiles instead but I think you already know that.

Also if you are working with Angular2 you may be interested in Microsofts JavaScriptServices package, which allows you to prerender the first request to the application server sided and the continue with client sided execution of it, speeding up the first laoding of the application as well as offering fallback routes.

Background: Angular2 doesn't use hash routes (example.com/myapp#/some/route) but uses hashless routes by default (example.com/myapp/some/route) which may cause an issue when you hit F5 in the browser while not in the app root url. The routes.MapSpaFallbackRoute call here will just route all requests to the SPA apps root.

It uses MVC however. Not sure how you do it w/o MVC, probably you'll need to wait for the URL Rewrite middleware which comes with ASP.NET Core 1.1.