在视图中有一个选择链接.单击时,将显示有关所选项目的详细信息
本文关键字:显示 选项 详细信息 项目 有一个 视图 选择 链接 单击 | 更新日期: 2024-10-25 02:52:48
我想添加允许用户选择资产的功能,并在他们选择时显示有关所选资产的其余信息。
这是我的索引视图:
@model IEnumerable<AssetManagementSystem.Models.Asset>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.AssetMake.Name)
</th>
<th>
@Html.DisplayNameFor(model => model.AssetType.Type)
</th>
<th>
@Html.DisplayNameFor(model => model.CPU.Name)
</th>
<th>
@Html.DisplayNameFor(model => model.Department.DepartmentName)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.AssetMake.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.AssetType.Type)
</td>
<td>
@Html.DisplayFor(modelItem => item.CPU.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Department.DepartmentName)
</td>
<td>
@Html.ActionLink("Select", "Index", new { id = item.AssetID }) |
@Html.ActionLink("Edit", "Edit", new { id=item.AssetID }) |
@Html.ActionLink("Details", "Details", new { id=item.AssetID }) |
@Html.ActionLink("Delete", "Delete", new { id=item.AssetID })
</td>
</tr>
}
</table>
基本上,我想在用户单击"选择"时显示有关资产的其余信息。
这是我的资产模型:
public class Asset
{
[Key]
public int AssetID { get; set; }
public int AssetMakeID { get; set; }
public int AssetTypeID { get; set; }
public string User { get; set; }
public int DepartmentID { get; set; }
public string AssetModel { get; set; }
public string AssetSerialNo { get; set; }
public string PurchaseOrderNo { get; set; }
public string Supplier { get; set; }
public string WarrantyInfo { get; set; }
public DateTime DatePurchased { get; set; }
public string ComputerName { get; set; }
public int CPUID { get; set; }
public string RAM { get; set; }
public string HardDrive { get; set; }
public int OperatingSystemID { get; set; }
public string OperatingSystemProductKey { get; set; }
public virtual AssetType AssetType { get; set; }
public virtual Department Department { get; set; }
public virtual CPU CPU { get; set; }
public virtual OperatingSyst OperatingSyst { get; set; }
public virtual AssetMake AssetMake { get; set; }
以下是我的资产控制器中的索引方法:
public ActionResult Index()
{
var asset = db.Asset
.Include(a => a.AssetMake)
.Include(a => a.AssetType)
.Include(a => a.CPU)
.Include(a => a.Department)
.Include(a => a.OperatingSyst);
return View(asset.ToList());
}
如何添加此功能以允许用户选择资产,然后显示资产信息?
你已经有了。
@Html.ActionLink("Details", "Details", new { id=item.AssetID })
然后在详细信息页面上放置要显示的其他信息的 Html 帮助程序。我正在使用MVC 6,但同样的事情可以应用于您使用的任何版本。target="_blank"只会在另一个选项卡中打开,以便他们可以轻松返回。
<a asp-action="Edit" asp-route-id="@item.AssetId">Edit</a> |
<a asp-action="Details" asp-route-id="@item.AssetId" target="_blank">Details</a> |
<a asp-action="Delete" asp-route-id="@item.AssetId">Delete</a>