在 MVC 中,当我们需要一个像下面这样的表单来创建我的模型的一个新项目时,我们在模型上添加一个强类型 View ,创建脚手架模板, 型号:
public class book
{
[Key]
public int BId { get; set; }
[Display(Name = "نام")]
public string name { get; set; }
[Display(Name = "نویسنده")]
public string writer { get; set; }
[Display(Name = "ناشر")]
public string publisher { get; set; }
[Display(Name = "سال انتشار")]
public string year { get; set; }
} `
结果是这样的:
@model مدرسه.Models.book
`@{
ViewBag.Title = "BookStore";
} `
` <h2>BookStore</h2>`
@using (Html.BeginForm()) {
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<fieldset>
<legend>book</legend>
<div class="editor-label">
@Html.LabelFor(model => model.name)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.name)
@Html.ValidationMessageFor(model => model.name)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.writer)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.writer)
@Html.ValidationMessageFor(model => model.writer)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.publisher)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.publisher)
@Html.ValidationMessageFor(model => model.publisher)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.year)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.year)
@Html.ValidationMessageFor(model => model.year)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
`}`
<div>
@Html.ActionLink("Back to List", "Index")
</div>
`@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
} `
此模板遵循此路径:
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\Web\Mvc\Scaffolding
我需要的是了解如何更改此文件以及实际上此文件是什么以及更改模板的哪一部分?
最佳答案
首先根据页面需求在 View 的Shared Folder
中创建一个自定义布局(模板)。
然后在脚手架上,选择布局(自定义模板)、模型等,然后单击确定。就这些
关于c# - 如何在 MVC 中自定义脚手架模板和更改 .cs.t4 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35284652/