为什么ASP.NET Core下的Bootstrap安装Razor? [英] Why does Bootstrap under ASP.NET Core install Razor?

查看:69
本文介绍了为什么ASP.NET Core下的Bootstrap安装Razor?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经部署了一个由Yeoman( yo aspnet )生成的Core网站,当被问到作为GUI管理器放入什么内容时,我有两个选择-Bootstrap和Semantic.我选择了Bootstrap,一切都进行得很好,但是...

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...

当我检查内容时,我意识到空的Web应用程序 web应用程序/引导程序之间的差异超出了我的预期.我得到了完整的MVC设置,其中包含视图,控制器等.所有视图当然都由Razor管理.

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.

所以我的问题是跳过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)?

我打算使用Angular2.在以后安装Bootstrap是否有意义?还是完全没有?

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

推荐答案

如果您所需要的只是wwwroot中的静态 index.html ,则不需要它.

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

默认情况下,yeoman必须安装MVC,默认情况下引导程序(NPM/Bower依赖项)只是一堆javascript&css文件.

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.

如果您需要控制器(用于WebAPI/REST服务调用,但不使用剃刀),则可以使用"Microsoft.AspNetCore.Mvc.Core":"1.0.1" 依赖性而​​不是"Microsoft.AspNetCore.Mvc":"1.0.1" .更高版本的软件包还提取了MVC所需的所有依赖关系,包括Razor.使用 Mvc.Core 软件包时,需要在 ConfigureServiuces()中的 AddMvcCore()中注册,而不是在 AddMvc()<中注册.

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().

如果您都不需要(因为您的WebAPI在另一个项目中),则只需删除依赖项.但是您需要 UseStaticFiles / UseDefaultFiles 代替,但是我想您已经知道这一点.

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.

如果您正在使用Angular2,您可能会对Microsoft的 JavaScriptServices 包感兴趣.将第一个请求预呈现给应用程序服务器端,并继续在客户端执行该请求,从而加快了应用程序的首次装载速度,并提供了后备路由.

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.

背景:Angular2不使用哈希路由(example.com/myapp#/some/route),但默认情况下使用无哈希路由(example.com/myapp/some/route),当您按F5时可能会引起问题在浏览器中而不是在应用程序根URL中. routes.MapSpaFallbackRoute 调用

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.

但是它使用MVC.不知道没有MVC怎么做,可能您需要等待

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.

这篇关于为什么ASP.NET Core下的Bootstrap安装Razor?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆