Asp.net mvc 传递一个id并从actionLink获取它以查看页面
我将此ActionLink链接到名为catalog的视图中Asp.net mvc 传递一个id并从actionLink获取它以查看页面,asp.net-mvc,view,controller,html.actionlink,Asp.net Mvc,View,Controller,Html.actionlink,我将此ActionLink链接到名为catalog的视图中 @Html.ActionLink("Formations", "Index", "Formation", new { id = item.Id },null) 我想得到这个目录id的结构列表 我该怎么做 在我的数据库中有两个表: Catalog:idC (PK),NameC,Date Formation:idF(PK),idC(FK),NameF. 如果视图的名称为Catalog,则需要更改ActionLink以指向相应的操作: @
@Html.ActionLink("Formations", "Index", "Formation", new { id = item.Id },null)
我想得到这个目录id的结构列表
我该怎么做
在我的数据库中有两个表:
Catalog:idC (PK),NameC,Date
Formation:idF(PK),idC(FK),NameF.
如果视图的名称为Catalog,则需要更改ActionLink以指向相应的操作:
@Html.ActionLink("Formations", "Catalog", "Formation", new { id = item.Id }, null)
行动:
public ActionResult Catalog(int id)
{
var formations = db.Formations.Where(f => f.idC == id).ToList;
return View(formations);
}
视图:
@model IEnumerable
//循环你的阵型
@foreach(模型中的var项目)
{
//每个编队迭代在这里循环
}
@model IEnumerable<ProjectName.Models.Formation>
// loop your formations
@foreach (var item in Model)
{
// each formation iteration loops here
}