【发布时间】:2015-02-11 20:56:24
【问题描述】:
我觉得这是一个非常基本的问题。我想要实现的是将对象集合显示为链接。当我点击一个链接时,我想被带到那个特定对象的详细信息。
我可以在索引视图上显示项目链接的集合,但是当我单击项目链接时,我可以显示 SingleProductView,但不能在那里显示该特定项目的变量。
是否可以通过 html.actionlink 将特定项目传递给视图?或者,是否可以将该特定项目传递给另一个将显示视图的操作?
型号:
public class ProductModel
{
public int ProductID { get; set; }
public string ProductName { get; set; }
public string ProductDescription { get; set; }
}
家庭控制器:
public class HomeController : Controller
{
List<ProductModel> inventory = new List<ProductModel>() {
new ProductModel { ProductName = "White T-Shirt", ProductDescription = "White T-Shirt", ListPrice = 10 },
new ProductModel { ProductName = "Black T-Shirt", ProductDescription = "Black T-Shirt", ListPrice = 10 },
};
public ActionResult Index()
{
return View(inventory);
}
[HttpGet]
public ActionResult SingleProductView()
{
return View();
}
}
索引视图:
@if(Model != null)
{
<ul>
@foreach (ProductModel item in Model)
{
<li>
@Html.ActionLink(item.ProductName, "SingleProductView")
</li>
}
</ul>
}
【问题讨论】:
标签: asp.net model actionresult html.actionlink