在MVC 5中,当您使用模型构建View,Create时 - 为了构建将绑定到模型的表单 - MVC 5中的scaffolder使用了列(col-md-10和col-md-2)将标签放在文本框的左侧:
<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", autocomplete = "off" } })
@Html.ValidationMessageFor(model => model.Username, "", new { @class = "text-danger" })
</div>
</div>
在Core MVC 2中,所有标签都在文本框之上 - 超级空间效率低:
<div class="form-group">
<label asp-for="Email" class="control-label"></label>
<input asp-for="Email" class="form-control" />
<span asp-validation-for="Email" class="text-danger"></span>
</div>
我可以手工编辑所有这些但是这会破坏脚手架的对象并且需要很长时间 .
有没有办法让脚手架使用以前的col类型布局 - 或者是否有任何第三方选项?
我在谷歌找不到任何东西 . 谢谢 .
1 回答
脚手架模板很容易根据您的喜好进行编辑 .
在Asp.Net Core MVC 2中,模板现在是cshtml而不是t4 .
您只需将模板复制到项目as explained here中,然后在下次运行脚手架时,它将使用您的模板而不是默认模板 .