<#@ template language="C#" HostSpecific="True" #>
<#@ output extension=".cshtml" #>
<#@ include file="Imports.include.t4" #>
@model IEnumerable<#= "<" + ViewDataTypeName + ">" #>
<#
// The following chained if-statement outputs the file header code and markup for a partial view, a view using a layout page, or a regular view.
if(IsPartialView) {
#>

<#
} else if(IsLayoutPageSelected) {
#>

@{
    ViewBag.Title = "<#= ViewName#>";
<#
if (!String.IsNullOrEmpty(LayoutPageFile)) {
#>
    Layout = "<#= LayoutPageFile#>";
<#
}
#>
}

<h2><#= ViewName#></h2>

<#
} else {
#>

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title><#= ViewName #></title>
</head>
<body>
<#
    PushIndent("    ");
}
#>
<p>
    @Html.ActionLink("Create New", "Create")
</p>
<table class="table" id="listGrid">
	<thead>
		<tr>
	<#
	IEnumerable<PropertyMetadata> properties = ModelMetadata.Properties;
	foreach (PropertyMetadata property in properties) {
		if (property.Scaffold && !property.IsPrimaryKey && !property.IsForeignKey) {
	#>
	<#
			// This is a temporary work around until core scaffolding provides support for independent associations.
			if (property.IsAssociation && GetRelatedModelMetadata(property) == null) {
				continue;
			}
	#>
			<th>
				@Html.DisplayNameFor(model => model.<#= GetValueExpression(property) #>)
			</th>
	<#
		}
	}
	#>
			<th>Actions</th>
		</tr>
	</thead>
	<tbody>
	@foreach (var item in Model) {
		<tr>
	<#
	foreach (PropertyMetadata property in properties) {
		if (property.Scaffold && !property.IsPrimaryKey && !property.IsForeignKey) {
	#>
	<#
			// This is a temporary work around until core scaffolding provides support for independent associations.
			if (property.IsAssociation && GetRelatedModelMetadata(property) == null) {
				continue;
			}
	#>
			<td>
				@Html.DisplayFor(modelItem => <#= "item." + GetValueExpression(property) #>)
			</td>
	<#
		}
	}

	string pkName = GetPrimaryKeyName();
	if (pkName != null) {
	#>
			<td>
				@Html.ActionLink("Edit", "Edit", new { id=item.<#= pkName #> }) |
				@Html.ActionLink("Details", "Details", new { id=item.<#= pkName #> }) |
				@Html.ActionLink("Delete", "Delete", new { id=item.<#= pkName #> })
			</td>
	<#
	} else {
	#>
			<td>
				@Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
				@Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
				@Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
			</td>
	<#
	}
	#>
		</tr>
	}
	<tbody>
</table>

@section scripts {
<script type="text/javascript">
	$(document).ready(function () {
		$("#listGrid").wijgrid({ allowSorting: true, allowPaging: true, pageSize: 20});
	});
</script>
}
<#
// The following code closes the tag used in the case of a view using a layout page and the body and html tags in the case of a regular view page
#>
<#
if(!IsPartialView && !IsLayoutPageSelected) {
    ClearIndent();
#>
</body>
</html>
<#
}
#>
<#@ include file="ModelMetadataFunctions.cs.include.t4" #>