xr2*_*0xr 10 asp.net-mvc asp.net-mvc-scaffolding asp.net-mvc-5 bootstrap-4 visual-studio-2017
我刚刚将我的Visual Studio 2017 ASP.NET MVC 5应用程序从Bootstrap v3更新到v4.我发现当我使用脚手架添加新的编辑局部视图时,它仍然使用表单的Bootstrap v3 CSS类名.有没有办法更新脚手架使用BS v4?
编辑
我正在谈论的内容似乎有些混乱.在Visual Studio 2017中,在MVC项目的"解决方案资源管理器"中,右键单击"视图"文件夹>"添加">"查看...">"MVC 5视图">"单击添加".这将打开"添加视图"对话框.我键入我的视图名称,选择编辑模板,然后选择,Views folder > Add > View... > MVC 5 View > Click Add作为Model类.Visual Studio生成此标记.这个过程叫做脚手架.
@model Demo.ViewModels.LoginVm
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>LoginVm</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.UserName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.UserName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.UserName, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Password, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Password, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Password, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
Run Code Online (Sandbox Code Playgroud)
注意正在使用的Bootstrap 3类,例如LoginVm和form-label.这些在Bootstrap 4中被删除.同样,如果你要创建一个新的Layout页面,它会生成一个Bootstrap 3 Navbar,它在Bootstrap 4中无效.所以我问是否有办法(没有编写自定义脚手架) )更新Visual Studio以停止输出Bootstrap 3特定标记,理想情况下,输出Bootstrap 4标记?
小智 0
VS中的脚手架引擎使用的模板是固定的。它们位于 VS 安装目录中(例如 %programfiles%\Microsoft Visual Studio\2017\Community\Common7\IDE\Extensions\Microsoft\Web\Mvc\Scaffolding\Templates\MvcView)。
因此,Bootstrap 3 类已固定在 MS 提供的 T4 文件中(当前标准是 BS3,当前在创建新的 MVC Web 项目时默认添加)。只需查看上面提到的目录中的“Edit.cs.t4”即可。您会在那里找到已弃用的 BS3 类,例如“btn-default”(在 BS4 中是 btn-secondary)。
如果您愿意,您可以创建自己的自定义 T4 模板。此任务的 MS 参考为: https: //learn.microsoft.com/en-us/visualstudio/modeling/code- Generation-and-t4-text-templates
| 归档时间: |
|
| 查看次数: |
2166 次 |
| 最近记录: |