【发布时间】:2017-08-25 11:09:19
【问题描述】:
我的索引页面显示 Azure SQL 数据库中的所有行。当我单击一行时,我会被重定向到一个带有该 URL 二维码的唯一 URL,并且它还仅显示该行的数据。每行都有自己的唯一 ID,但也有一个卡车 ID。 TruckID 适用于可以“拥有”多行数据的驾驶员,因此我希望在单击一行后显示每一行都具有相同的 truckID。
这是我目前所得到的:
型号
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; }
}
}
查看(从索引中单击一行后)
@model QR.data
@{
ViewBag.Title = "Details";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>QR code</h2>
<img src="/Home/BarcodeImage?barcodeText=@Request.Url.OriginalString"/>
<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(),但您的视图也需要一些工作。 ..
标签: c# mysql asp.net asp.net-mvc azure