.Net Core 2.0 带 Razor 页面的向下钻取功能
.Net Core 2.0 Drill down functionality w/ Razor Pages
目前我正在学习 razor pages 并且有 WPF 背景。
我正在以行格式显示一些数据,但想创建如下的向下钻取格式:http://jsfiddle.net/zey3h41o/
我可以从一个模型创建顶级数据的摘要,然后创建一个向下钻取功能,显示数据结构的子条目,例如:
List<Tuple<HighLevelOutput, List<HighLevelOutput>>>
和模型
public struct HighLevelOutput
{
public string CorpCustomer { get; set; }
public string Item { get; set; }
public string ItemDescription { get; set; }
public double SummedOrder { get; set; }
public double SummedForecast { get; set; }
public int Week { get; set; }
public double Difference { get; set; }
public string UoM { get; set; }
}
我的剃刀页面:
@page
@model DemandControlTool.Pages.CalculateLogModel
@{
ViewData["Title"] = "CalculateLog";
}
<h3>Abnormal Demand</h3>
<table class="table">
<thead>
<tr>
<th></th>
<th>
@Html.DisplayNameFor(model => model.ReportHighLevel[0].CorpCustomer)
</th>
<th>
@Html.DisplayNameFor(model => model.ReportHighLevel[0].Item)
</th>
<th class="text-center">
@Html.DisplayNameFor(model => model.ReportHighLevel[0].SummedOrder)
</th>
<th class="text-center">
@Html.DisplayNameFor(model => model.ReportHighLevel[0].SummedForecast)
</th>
<th class="text-center">
@Html.DisplayNameFor(model => model.ReportHighLevel[0].Difference)
</th>
</tr>
</thead>
</table>
<table class="log">
<thead class="log">
@foreach (var item in Model.DropDownAllOrders)
{
<tr>
<th>
@Html.DisplayFor(modelItem => item.Item1.Item)
</th>
<th>
@Html.DisplayFor(modelItem => item.Item1.ItemDescription)
</th>
<th>
@Html.DisplayFor(modelItem => item.Item1.CorpCustomer)
</th>
<th class="text-center">
@Html.DisplayFor(modelItem => item.Item1.SummedOrder)
</th>
<th class="text-center">
@Html.DisplayFor(modelItem => item.Item1.SummedForecast)
</th>
<th class="text-center">
@Html.DisplayFor(modelItem => item.Item1.Difference)
</th>
</tr>
}
</thead>
<tbody class="collapsed">
<tr><td>Drill Down Data</td></tr>
<tr><td>Drill Down Data</td></tr>
</tbody>
</table>
我遇到的问题是填充 table,我可以在其中每行下方折叠条目。按照我一直在玩的方式,我需要为列表中的每个对象定义一个单独的行。我希望正文 class 有每个摘要行的列表。
在上面的示例中,折叠的主体仅出现在底行下方。
更新编辑:
@page
@model DemandControlTool.Pages.CalculateLogModel
@{
ViewData["Title"] = "CalculateLog";
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<link href="~/bootstrap.css" rel="stylesheet" />
<title>Data page</title>
</head>
<body>
<div class="container">
<div id="accordion">
@{int counter = 0; }
@foreach (var dataVM in Model.CollapseReport)
{
<div class="card">
<div class="card-header" id="heading@(counter)">
<h5 class="mb-0">
<button class="btn btn-link" data-toggle="collapse"
data-target="#collapse@(counter)" aria-expanded="true" aria-
controls="collapse@(counter)">
@dataVM.ToString()
</button>
</h5>
</div>
<div id="collapse@(counter)" class="collapse" aria-
labelledby="heading@(counter)" data-parent="#accordion">
<div class="card-body">
<ul class="list-group">
@foreach (var item in dataVM.WeeksOfData)
{
<li class="list-group-item col-xs-6">@item.Item</li>
<li class="list-group-item col-xs-6">@item.ItemDescription</li>
<li class="list-group-item col-xs-6">@item.CorpCustomer</li>
<li class="list-group-item col-xs-6">@item.Difference</li>
<li class="list-group-item col-xs-6">@item.Week</li>
}
</ul>
</div>
</div>
</div>
counter++;
}
</div>
</div>
<script src="~/jquery.min.js"></script>
<script src="~/bootstrap.bundle.min.js"></script>
</body>
</html>
根据您提供的示例,我为您的问题考虑了一个不同的解决方案,我认为它更简单并且更适合网络,首先我使用了 JQuery 和Bootstrap v.4 在我的 front-end 代码中,然后我使用了两个组件,它们是:
然后我为我的数据形状创建了一个视图模型,其中包含一个带有项目列表的标题(我使用字符串仅用于演示)如下:
public class DataViewModel
{
public string Title { get; set; }
public IEnumerable<string> Data { get; set; }
}
并创建一个索引操作如下(只是为了填充一些数据并将其传递给视图:
public IActionResult Index()
{
var pageViewModel = new List<DataViewModel>()
{
new DataViewModel()
{
Title="First data tab",
Data=new string []{"Item 1","Item 2","Item 3"}
},
new DataViewModel()
{
Title="Second data tab",
Data=new string []{"Item 1","Item 2","Item 3"}
}
};
return View(pageViewModel);
}
最后查看代码如下:
@model IEnumerable<ProgrammerGallery.Controllers.DataViewModel>
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<link href="~/bootstrap.min.css" rel="stylesheet" />
<title>Data page</title>
</head>
<body>
<div class="container">
<div id="accordion">
@{int counter = 0; }
@foreach (var dataVM in Model)
{
<div class="card">
<div class="card-header" id="heading@(counter)">
<h5 class="mb-0">
<button class="btn btn-link" data-toggle="collapse" data-target="#collapse@(counter)" aria-expanded="true" aria-controls="collapse@(counter)">
@dataVM.Title
</button>
</h5>
</div>
<div id="collapse@(counter)" class="collapse show" aria-labelledby="heading@(counter)" data-parent="#accordion">
<div class="card-body">
<ul class="list-group">
@foreach (var item in dataVM.Data)
{
<li class="list-group-item">@item</li>
}
</ul>
</div>
</div>
</div>
counter++;
}
</div>
</div>
<script src="~/jquery.min.js"></script>
<script src="~/bootstrap.bundle.min.js"></script>
</body>
</html>
最后的结果是:
第二版(在并排显示实体数据而不是字符串数据旁边呈现页面时的可折叠项):
实体class:
public class Entity
{
public string Name { get; set; }
public string BriefDescription { get; set; }
public double Price { get; set; }
}
查看模型class:
public class DataViewModel
{
public string Title { get; set; }
public IEnumerable<Entity> Data { get; set; }
}
动作:
public IActionResult Index()
{
var pageViewModel = new List<DataViewModel>()
{
new DataViewModel()
{
Title="First data tab",
Data=new List<Entity>()
{
new Entity()
{
Name="First item",
BriefDescription="My description",
Price=1000
},
new Entity()
{
Name="Second",
BriefDescription="My description",
Price=500
},
new Entity()
{
Name="Third",
BriefDescription="My description",
Price=1000
}
}
},
new DataViewModel()
{
Title="Second data tab",
Data=new List<Entity>()
{
new Entity()
{
Name="First item",
BriefDescription="My description",
Price=1000
},
new Entity()
{
Name="Second",
BriefDescription="My description",
Price=500
},
new Entity()
{
Name="Third",
BriefDescription="My description",
Price=1000
}
}
}
};
return View(pageViewModel);
}
最后是剃须刀代码:
@model IEnumerable<ProgrammerGallery.Controllers.DataViewModel>
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<link href="~/bootstrap.min.css" rel="stylesheet" />
<title>Data page</title>
</head>
<body>
<div class="container">
<div id="accordion">
@{int counter = 0; }
@foreach (var dataVM in Model)
{
<div class="card">
<div class="card-header" id="heading@(counter)">
<h5 class="mb-0">
<button class="btn btn-link" data-toggle="collapse" data-target="#collapse@(counter)" aria-expanded="true" aria-controls="collapse@(counter)">
@dataVM.Title
</button>
</h5>
</div>
<div id="collapse@(counter)" class="collapse" aria-labelledby="heading@(counter)" data-parent="#accordion">
<div class="card-body">
<ul class="list-group">
@foreach (var item in dataVM.Data)
{
<li class="list-group-item">@($"Name :{item.Name}, {item.BriefDescription}, {item.Price}$")</li>
}
</ul>
</div>
</div>
</div>
counter++;
}
</div>
</div>
<script src="~/jquery.min.js"></script>
<script src="~/bootstrap.bundle.min.js"></script>
</body>
</html>
目前我正在学习 razor pages 并且有 WPF 背景。
我正在以行格式显示一些数据,但想创建如下的向下钻取格式:http://jsfiddle.net/zey3h41o/
我可以从一个模型创建顶级数据的摘要,然后创建一个向下钻取功能,显示数据结构的子条目,例如:
List<Tuple<HighLevelOutput, List<HighLevelOutput>>>
和模型
public struct HighLevelOutput
{
public string CorpCustomer { get; set; }
public string Item { get; set; }
public string ItemDescription { get; set; }
public double SummedOrder { get; set; }
public double SummedForecast { get; set; }
public int Week { get; set; }
public double Difference { get; set; }
public string UoM { get; set; }
}
我的剃刀页面:
@page
@model DemandControlTool.Pages.CalculateLogModel
@{
ViewData["Title"] = "CalculateLog";
}
<h3>Abnormal Demand</h3>
<table class="table">
<thead>
<tr>
<th></th>
<th>
@Html.DisplayNameFor(model => model.ReportHighLevel[0].CorpCustomer)
</th>
<th>
@Html.DisplayNameFor(model => model.ReportHighLevel[0].Item)
</th>
<th class="text-center">
@Html.DisplayNameFor(model => model.ReportHighLevel[0].SummedOrder)
</th>
<th class="text-center">
@Html.DisplayNameFor(model => model.ReportHighLevel[0].SummedForecast)
</th>
<th class="text-center">
@Html.DisplayNameFor(model => model.ReportHighLevel[0].Difference)
</th>
</tr>
</thead>
</table>
<table class="log">
<thead class="log">
@foreach (var item in Model.DropDownAllOrders)
{
<tr>
<th>
@Html.DisplayFor(modelItem => item.Item1.Item)
</th>
<th>
@Html.DisplayFor(modelItem => item.Item1.ItemDescription)
</th>
<th>
@Html.DisplayFor(modelItem => item.Item1.CorpCustomer)
</th>
<th class="text-center">
@Html.DisplayFor(modelItem => item.Item1.SummedOrder)
</th>
<th class="text-center">
@Html.DisplayFor(modelItem => item.Item1.SummedForecast)
</th>
<th class="text-center">
@Html.DisplayFor(modelItem => item.Item1.Difference)
</th>
</tr>
}
</thead>
<tbody class="collapsed">
<tr><td>Drill Down Data</td></tr>
<tr><td>Drill Down Data</td></tr>
</tbody>
</table>
我遇到的问题是填充 table,我可以在其中每行下方折叠条目。按照我一直在玩的方式,我需要为列表中的每个对象定义一个单独的行。我希望正文 class 有每个摘要行的列表。
在上面的示例中,折叠的主体仅出现在底行下方。
更新编辑:
@page
@model DemandControlTool.Pages.CalculateLogModel
@{
ViewData["Title"] = "CalculateLog";
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<link href="~/bootstrap.css" rel="stylesheet" />
<title>Data page</title>
</head>
<body>
<div class="container">
<div id="accordion">
@{int counter = 0; }
@foreach (var dataVM in Model.CollapseReport)
{
<div class="card">
<div class="card-header" id="heading@(counter)">
<h5 class="mb-0">
<button class="btn btn-link" data-toggle="collapse"
data-target="#collapse@(counter)" aria-expanded="true" aria-
controls="collapse@(counter)">
@dataVM.ToString()
</button>
</h5>
</div>
<div id="collapse@(counter)" class="collapse" aria-
labelledby="heading@(counter)" data-parent="#accordion">
<div class="card-body">
<ul class="list-group">
@foreach (var item in dataVM.WeeksOfData)
{
<li class="list-group-item col-xs-6">@item.Item</li>
<li class="list-group-item col-xs-6">@item.ItemDescription</li>
<li class="list-group-item col-xs-6">@item.CorpCustomer</li>
<li class="list-group-item col-xs-6">@item.Difference</li>
<li class="list-group-item col-xs-6">@item.Week</li>
}
</ul>
</div>
</div>
</div>
counter++;
}
</div>
</div>
<script src="~/jquery.min.js"></script>
<script src="~/bootstrap.bundle.min.js"></script>
</body>
</html>
根据您提供的示例,我为您的问题考虑了一个不同的解决方案,我认为它更简单并且更适合网络,首先我使用了 JQuery 和Bootstrap v.4 在我的 front-end 代码中,然后我使用了两个组件,它们是:
然后我为我的数据形状创建了一个视图模型,其中包含一个带有项目列表的标题(我使用字符串仅用于演示)如下:
public class DataViewModel
{
public string Title { get; set; }
public IEnumerable<string> Data { get; set; }
}
并创建一个索引操作如下(只是为了填充一些数据并将其传递给视图:
public IActionResult Index()
{
var pageViewModel = new List<DataViewModel>()
{
new DataViewModel()
{
Title="First data tab",
Data=new string []{"Item 1","Item 2","Item 3"}
},
new DataViewModel()
{
Title="Second data tab",
Data=new string []{"Item 1","Item 2","Item 3"}
}
};
return View(pageViewModel);
}
最后查看代码如下:
@model IEnumerable<ProgrammerGallery.Controllers.DataViewModel>
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<link href="~/bootstrap.min.css" rel="stylesheet" />
<title>Data page</title>
</head>
<body>
<div class="container">
<div id="accordion">
@{int counter = 0; }
@foreach (var dataVM in Model)
{
<div class="card">
<div class="card-header" id="heading@(counter)">
<h5 class="mb-0">
<button class="btn btn-link" data-toggle="collapse" data-target="#collapse@(counter)" aria-expanded="true" aria-controls="collapse@(counter)">
@dataVM.Title
</button>
</h5>
</div>
<div id="collapse@(counter)" class="collapse show" aria-labelledby="heading@(counter)" data-parent="#accordion">
<div class="card-body">
<ul class="list-group">
@foreach (var item in dataVM.Data)
{
<li class="list-group-item">@item</li>
}
</ul>
</div>
</div>
</div>
counter++;
}
</div>
</div>
<script src="~/jquery.min.js"></script>
<script src="~/bootstrap.bundle.min.js"></script>
</body>
</html>
最后的结果是:
第二版(在并排显示实体数据而不是字符串数据旁边呈现页面时的可折叠项):
实体class:
public class Entity
{
public string Name { get; set; }
public string BriefDescription { get; set; }
public double Price { get; set; }
}
查看模型class:
public class DataViewModel
{
public string Title { get; set; }
public IEnumerable<Entity> Data { get; set; }
}
动作:
public IActionResult Index()
{
var pageViewModel = new List<DataViewModel>()
{
new DataViewModel()
{
Title="First data tab",
Data=new List<Entity>()
{
new Entity()
{
Name="First item",
BriefDescription="My description",
Price=1000
},
new Entity()
{
Name="Second",
BriefDescription="My description",
Price=500
},
new Entity()
{
Name="Third",
BriefDescription="My description",
Price=1000
}
}
},
new DataViewModel()
{
Title="Second data tab",
Data=new List<Entity>()
{
new Entity()
{
Name="First item",
BriefDescription="My description",
Price=1000
},
new Entity()
{
Name="Second",
BriefDescription="My description",
Price=500
},
new Entity()
{
Name="Third",
BriefDescription="My description",
Price=1000
}
}
}
};
return View(pageViewModel);
}
最后是剃须刀代码:
@model IEnumerable<ProgrammerGallery.Controllers.DataViewModel>
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<link href="~/bootstrap.min.css" rel="stylesheet" />
<title>Data page</title>
</head>
<body>
<div class="container">
<div id="accordion">
@{int counter = 0; }
@foreach (var dataVM in Model)
{
<div class="card">
<div class="card-header" id="heading@(counter)">
<h5 class="mb-0">
<button class="btn btn-link" data-toggle="collapse" data-target="#collapse@(counter)" aria-expanded="true" aria-controls="collapse@(counter)">
@dataVM.Title
</button>
</h5>
</div>
<div id="collapse@(counter)" class="collapse" aria-labelledby="heading@(counter)" data-parent="#accordion">
<div class="card-body">
<ul class="list-group">
@foreach (var item in dataVM.Data)
{
<li class="list-group-item">@($"Name :{item.Name}, {item.BriefDescription}, {item.Price}$")</li>
}
</ul>
</div>
</div>
</div>
counter++;
}
</div>
</div>
<script src="~/jquery.min.js"></script>
<script src="~/bootstrap.bundle.min.js"></script>
</body>
</html>