如何使用 ASP.NET MVC link 列表 table 视图到另一个 table 视图的详细信息
How to link a list table view to another table view for details using ASP.NET MVC
我在第 1 页上查看列表,在第 2 页上它应该 link 在第 1 页上使用数据库中的相同 ID,但在第 2 页上使用其详细信息页面。
第 1 页 - 列表视图
第 2 页 - 详细信息
这是我已经尝试过的方法
示例:http://abctutorial.com/Post/53/mvc5-master-detail-edit-using-aspnet--jquery--razor
名为“Ordering”的模型及其在 ListView 上的显示
public Ordering()
{
this.Invoice_Line_Item = new HashSet<Invoice_Line_Items>();
}
[Key]
public int order_id { get; set; }
public Guid? CustomerId { get; set; }
public int? CustId { get; set; }
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
[StringLength(34)]
public string invoice_number { get; set; }
[StringLength(200)]
public string EmailId { get; set; }
[StringLength(50)]
public string ClientFirstname { get; set; }
[StringLength(50)]
public string ClientLastname { get; set; }
[StringLength(50)]
public string MobileNumber { get; set; }
[StringLength(50)]
public string PaymentStatus { get; set; }
[StringLength(50)]
public string trackingorderno { get; set; }
[StringLength(50)]
public string Status { get; set; }
[StringLength(200)]
public string DeliveryNote { get; set; }
[StringLength(250)]
public string Agent { get; set; }
public DateTime? date_order_placed { get; set; }
public virtual ICollection<Invoice_Line_Items> Invoice_Line_Item {
get; set; }
“订购”的列表视图页面
@model IEnumerable<LifestyleAdminOriginal.Models.Ordering>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.invoice_number)
</td>
<td>
@Html.DisplayFor(modelItem => item.ClientFirstname) @Html.DisplayFor(modelItem => item.ClientLastname)
</td>
<td>
@Html.DisplayFor(modelItem => item.EmailId)
</td>
<td>
@Html.DisplayFor(modelItem => item.MobileNumber)
</td>
<td>
<span class="label label-danger">@Html.DisplayFor(modelItem => item.Status)</span>
</td>
<td>
@Html.ActionLink("View", "NewOrdersDetails", new { id = item.CustId })
</td>
</tr>
}
“Invoice_Line_Items”的详细信息页面
<div class="row">
@if (Model.Count() != 0)
{
foreach (var item in Model)
{
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="invoice-sp">
<table class="table table-hover">
<thead>
<tr>
<th>Service</th>
<th>Item</th>
<th>Gender</th>
<th>Unit Price</th>
<th>Quantity</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<tr>
@foreach (var inv in item.Invoice_Line_Item)
{
<th>@inv.service</th>
<td>@inv.item</td>
<td>@inv.gender</td>
<td>@inv.price</td>
<td>@inv.quantity</td>
<td>@inv.price</td>
}
</tr>
</tbody>
</table>
</div>
</div>
}
}
</div>
用于“排序”的列表视图控制器
public ActionResult NewOrders()
{
var count = db.Orderings.Where(s => s.trackingorderno == "New Order").Count();
ViewBag.totalall = count;
return View(db.Orderings.ToList().Where(x => x.trackingorderno == "New Order").Select(x => x));
}
“Invoice_Line_Items”和“订购”的详细视图控制器
public ActionResult NewOrdersDetails(int? CustId)
{
if (CustId == null)
{
return new System.Web.Mvc.HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
List<Ordering> OrderAndCustomerList = db.Orderings.ToList();
if (OrderAndCustomerList == null)
{
return HttpNotFound();
}
return View(OrderAndCustomerList);
}
基本上,每当用户在列表视图页面上单击“查看”时,都应该将他们带到详细信息页面,其中显示发票行项目并在“DetailsView”页面上显示客户详细信息
第一个 table 显示主要数据的位置,第二个 Table 第一个 table 数据的详细信息
所以你必须在 Main Table content 中获取 detail table content id 并将其发送到第二页,其中包含来自 main table.
的 detail id
我设法从下面 link 上的以下示例中得到了答案。我在模型 Ordering
上使用了 ICollection
**Ordering Model**
[ForeignKey("order_id")]
public virtual ICollection<Invoice_Line_Items> Invoice_Line_Item { get; set; }
**Invoice_Line_Items Model**
public virtual Ordering Ordering { get; set; }
**Details Page**
<table class="table">
<tr>
<th>Service</th>
<th>Department</th>
</tr>
@foreach (var item in Model.Invoice_Line_Item)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.invoice_number)
</td>
<td>
@Html.DisplayFor(modelItem => item.service)
</td>
<td>
@Html.DisplayFor(modelItem => item.department)
</td>
<td>
@Html.DisplayFor(modelItem => item.item)
</td>
<td>
@Html.DisplayFor(modelItem => item.quantity)
</td>
<td>
@Html.DisplayFor(modelItem => item.price)
</td>
<td>
@Html.DisplayFor(modelItem => item.vat)
</td>
<td>
@Html.DisplayFor(modelItem => item.grandtotal)
</td>
</tr>
}
</table>
我在第 1 页上查看列表,在第 2 页上它应该 link 在第 1 页上使用数据库中的相同 ID,但在第 2 页上使用其详细信息页面。
第 1 页 - 列表视图
第 2 页 - 详细信息
这是我已经尝试过的方法
示例:http://abctutorial.com/Post/53/mvc5-master-detail-edit-using-aspnet--jquery--razor
名为“Ordering”的模型及其在 ListView 上的显示
public Ordering()
{
this.Invoice_Line_Item = new HashSet<Invoice_Line_Items>();
}
[Key]
public int order_id { get; set; }
public Guid? CustomerId { get; set; }
public int? CustId { get; set; }
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
[StringLength(34)]
public string invoice_number { get; set; }
[StringLength(200)]
public string EmailId { get; set; }
[StringLength(50)]
public string ClientFirstname { get; set; }
[StringLength(50)]
public string ClientLastname { get; set; }
[StringLength(50)]
public string MobileNumber { get; set; }
[StringLength(50)]
public string PaymentStatus { get; set; }
[StringLength(50)]
public string trackingorderno { get; set; }
[StringLength(50)]
public string Status { get; set; }
[StringLength(200)]
public string DeliveryNote { get; set; }
[StringLength(250)]
public string Agent { get; set; }
public DateTime? date_order_placed { get; set; }
public virtual ICollection<Invoice_Line_Items> Invoice_Line_Item {
get; set; }
“订购”的列表视图页面
@model IEnumerable<LifestyleAdminOriginal.Models.Ordering>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.invoice_number)
</td>
<td>
@Html.DisplayFor(modelItem => item.ClientFirstname) @Html.DisplayFor(modelItem => item.ClientLastname)
</td>
<td>
@Html.DisplayFor(modelItem => item.EmailId)
</td>
<td>
@Html.DisplayFor(modelItem => item.MobileNumber)
</td>
<td>
<span class="label label-danger">@Html.DisplayFor(modelItem => item.Status)</span>
</td>
<td>
@Html.ActionLink("View", "NewOrdersDetails", new { id = item.CustId })
</td>
</tr>
}
“Invoice_Line_Items”的详细信息页面
<div class="row">
@if (Model.Count() != 0)
{
foreach (var item in Model)
{
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="invoice-sp">
<table class="table table-hover">
<thead>
<tr>
<th>Service</th>
<th>Item</th>
<th>Gender</th>
<th>Unit Price</th>
<th>Quantity</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<tr>
@foreach (var inv in item.Invoice_Line_Item)
{
<th>@inv.service</th>
<td>@inv.item</td>
<td>@inv.gender</td>
<td>@inv.price</td>
<td>@inv.quantity</td>
<td>@inv.price</td>
}
</tr>
</tbody>
</table>
</div>
</div>
}
}
</div>
用于“排序”的列表视图控制器
public ActionResult NewOrders()
{
var count = db.Orderings.Where(s => s.trackingorderno == "New Order").Count();
ViewBag.totalall = count;
return View(db.Orderings.ToList().Where(x => x.trackingorderno == "New Order").Select(x => x));
}
“Invoice_Line_Items”和“订购”的详细视图控制器
public ActionResult NewOrdersDetails(int? CustId)
{
if (CustId == null)
{
return new System.Web.Mvc.HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
List<Ordering> OrderAndCustomerList = db.Orderings.ToList();
if (OrderAndCustomerList == null)
{
return HttpNotFound();
}
return View(OrderAndCustomerList);
}
基本上,每当用户在列表视图页面上单击“查看”时,都应该将他们带到详细信息页面,其中显示发票行项目并在“DetailsView”页面上显示客户详细信息
第一个 table 显示主要数据的位置,第二个 Table 第一个 table 数据的详细信息 所以你必须在 Main Table content 中获取 detail table content id 并将其发送到第二页,其中包含来自 main table.
的 detail id我设法从下面 link 上的以下示例中得到了答案。我在模型 Ordering
上使用了 ICollection **Ordering Model**
[ForeignKey("order_id")]
public virtual ICollection<Invoice_Line_Items> Invoice_Line_Item { get; set; }
**Invoice_Line_Items Model**
public virtual Ordering Ordering { get; set; }
**Details Page**
<table class="table">
<tr>
<th>Service</th>
<th>Department</th>
</tr>
@foreach (var item in Model.Invoice_Line_Item)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.invoice_number)
</td>
<td>
@Html.DisplayFor(modelItem => item.service)
</td>
<td>
@Html.DisplayFor(modelItem => item.department)
</td>
<td>
@Html.DisplayFor(modelItem => item.item)
</td>
<td>
@Html.DisplayFor(modelItem => item.quantity)
</td>
<td>
@Html.DisplayFor(modelItem => item.price)
</td>
<td>
@Html.DisplayFor(modelItem => item.vat)
</td>
<td>
@Html.DisplayFor(modelItem => item.grandtotal)
</td>
</tr>
}
</table>