我的索引頁面顯示來自Azure SQL數據庫的所有行。當我點擊一行時,我會被重定向到一個具有該URL的QR碼的唯一URL,並且它也會顯示該行的數據。每行都有它自己的唯一ID,但也有一個卡車ID。卡車ID是可以「擁有」多行數據的驅動程序,所以我想在單擊行後顯示具有相同卡車ID的每一行。如何在ASP.NET MVC中顯示具有相同ID的所有行?
這是我到目前爲止有:
模型
namespace QR
{
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.Spatial;
[Table("data")]
public partial class data
{
[Required]
[StringLength(50)]
public string Contract { get; set; }
[StringLength(50)]
public string Sort { get; set; }
public int? Report { get; set; }
public double? InputKG { get; set; }
public double? OutputKG { get; set; }
public double? Recovery { get; set; }
public double? Si { get; set; }
public double? Cu { get; set; }
public double? Mn { get; set; }
public double? Mg { get; set; }
public double? Zn { get; set; }
public double? Cr { get; set; }
public double? Fe { get; set; }
public double? Pb { get; set; }
public int? truckID { get; set; }
[Key]
public int ID{ get; set; }
}
}
VIEW(行從指數點擊後)
@model QR.data
@{
ViewBag.Title = "Details";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>QR code</h2>
<img src="/Home/[email protected]"/>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.Contract)
</th>
<th>
@Html.DisplayNameFor(model => model.Sort)
</th>
<th>
@Html.DisplayNameFor(model => model.Report)
</th>
<th>
@Html.DisplayNameFor(model => model.InputKG)
</th>
<th>
@Html.DisplayNameFor(model => model.OutputKG)
</th>
<th>
@Html.DisplayNameFor(model => model.Recovery)
</th>
<th>
@Html.DisplayNameFor(model => model.Si)
</th>
<th>
@Html.DisplayNameFor(model => model.Cu)
</th>
<th>
@Html.DisplayNameFor(model => model.Mn)
</th>
<th>
@Html.DisplayNameFor(model => model.Mg)
</th>
<th>
@Html.DisplayNameFor(model => model.Zn)
</th>
<th>
@Html.DisplayNameFor(model => model.Cr)
</th>
<th>
@Html.DisplayNameFor(model => model.Fe)
</th>
<th>
@Html.DisplayNameFor(model => model.Pb)
</th>
</tr>
<tr>
<td>
@Html.DisplayFor(model => model.Contract)
</td>
<td>
@Html.DisplayFor(model => model.Sort)
</td>
<td>
@Html.DisplayFor(model => model.Report)
</td>
<td>
@Html.DisplayFor(model => model.InputKG)
</td>
<td>
@Html.DisplayFor(model => model.OutputKG)
</td>
<td>
@Html.DisplayFor(model => model.Recovery)
</td>
<td>
@Html.DisplayFor(model => model.Si)
</td>
<td>
@Html.DisplayFor(model => model.Cu)
</td>
<td>
@Html.DisplayFor(model => model.Mn)
</td>
<td>
@Html.DisplayFor(model => model.Mg)
</td>
<td>
@Html.DisplayFor(model => model.Zn)
</td>
<td>
@Html.DisplayFor(model => model.Cr)
</td>
<td>
@Html.DisplayFor(model => model.Fe)
</td>
<td>
@Html.DisplayFor(model => model.Pb)
</td>
</tr>
</table>
<p>
@Html.ActionLink("Back to List", "Index")
</p>
控制器
public ActionResult Details(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
data data= db.data.Find(id);
if (data == null)
{
return HttpNotFound();
}
return View(data);
}
而在索引上我有這個鏈接:
@Html.ActionLink("QR", "Details", new { id = item.ID})
幫助?
我看不出你是如何將你的TruckID整合到任何地方的數據/視圖中的......你的查詢可能類似於'data data = db.data.Where(x => x.TruckID = YourTruckIDVariable ).ToList()',但您的視圖也需要一些工作以及... – jleach