デフォルト ビュー テンプレートの MVC デフォルト生成を次のようにスキャフォールディングします。
_CreateOrEdit
Edit
Create
Index
今、次のようなテンプレートを作成したい
_CreateOrEdit
Edit
Create
Index
and new template _Index as subview in Index for PageListMVC
それを行う方法を私に提案してもらえますか。
デフォルト ビュー テンプレートの MVC デフォルト生成を次のようにスキャフォールディングします。
_CreateOrEdit
Edit
Create
Index
今、次のようなテンプレートを作成したい
_CreateOrEdit
Edit
Create
Index
and new template _Index as subview in Index for PageListMVC
それを行う方法を私に提案してもらえますか。
1.) 次の場所に移動します: C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\ItemTemplates\CSharp\Web\MVC 4\CodeTemplates\AddView\CSHTML
2.) そのフォルダーをソリューションにコピーし、「CodeTemplates」というフォルダー内に配置します。
3.) List.tt を除く内部のすべてのファイルを削除します (使用していない限り、このフォルダーにはファイルがありません。これが完了したら、このフォルダーに元々あった他のファイルごとにプロセスを繰り返すことができます。 )
4.) List.tt ファイルの変更のプロパティで
Build Action: NONE
Browse To Url: BLANK
Copy to Output Dir: DO NOT COPY
5.) ファイルの名前を List_Div に変更し、必要に応じてファイルを編集します。その後、足場に移動すると、 List_Div が新しいオプションになります。この機能が必要なすべてのプロジェクトでこれを行う必要があります。ただし、新しいプロジェクトを開始するときに、ディレクトリを各プロジェクトにコピーするだけです。Bootstrap プロジェクト、FOundatons プロジェクトなど専用の Views フォルダーがあります。
私の Foundation List_F5 ファイルがどのように見えるかの例を示します。変更する必要がある重要な行のみを示します (およそ 49 行目から 128 行目:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title><#= mvcHost.ViewName #></title>
</head>
<body>
<#
PushIndent(" ");
}
#>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<div class="row">
<div class="large-12 columns">
<#
List<ModelProperty> properties = GetModelProperties(mvcHost.ViewDataType);
foreach (ModelProperty property in properties) {
if (!property.IsPrimaryKey && property.Scaffold) {
#>
<div class="medium-1 columns">
@Html.DisplayNameFor(model => model.<#= property.ValueExpression #>)
</div>
<#
}
}
#>
<div class="medium-3 columns"></div>
</div>
@foreach (var item in Model) {
<div class="medium-12 columns">
<#
foreach (ModelProperty property in properties) {
if (!property.IsPrimaryKey && property.Scaffold) {
#>
<div class="medium-1 columns">
@Html.DisplayFor(modelItem => <#= property.ItemValueExpression #>)
</div>
<#
}
}
string pkName = GetPrimaryKeyName(mvcHost.ViewDataType);
if (pkName != null) {
#>
<div class="medium-3 columns">
<a href="@Url.Action("Edit", "Edit", new { id=item.<#= pkName #> })"><i class="fa fa-pencil"></i></a> |
<a href="@Url.Action("Details", "Details", new { id=item.<#= pkName #> })"><i class="fa fa-file"></i></a> |
<a href="@Url.Action("Delete", "Delete", new { id=item.<#= pkName #> })"><i class="fa fa-times"></i></a>
</div>
<#
} else {
#>
<div class="medium-3 columns">
<a href='@Url.Action("Edit", "Edit", new { /* id=item.PrimaryKey */ })"><i class="fa fa-pencil"></i></a> |
<a href="@Url.Action("Details", "Details", new { /* id=item.PrimaryKey */ })"><i class="fa fa-file"></i></a> |
<a href="@Url.Action("Delete", "Delete", new { /* id=item.PrimaryKey */ })"><i class="fa fa-times"></i></a>
</div>
<#
}
#>
</div>
}
</div>
<#
// The following code closes the asp:Content tag used in the case of a master page and the body and html tags in the case of a regular view page
#>
<#
if(mvcHost.IsContentPage) {
#>
<#
} else if(!mvcHost.IsPartialView && !mvcHost.IsContentPage) {
ClearIndent();
#>
</body>
</html>