[英]How to send item through ActionLink to ASP.NET MVC controller?
Here I have some rows in a table and am listing out the flags for my products which in this case is called item. 在这里,我在表中有一些行,并且列出了我的产品的标志,在这种情况下称为商品。 When I want to edit the flags as on or off (yes/no), I need to get access to the whole item itself as I have no other way of identifying which item's flag I clicked on. 当我想将标记编辑为打开或关闭(是/否)时,我需要访问整个项目本身,因为我没有其他方法可以识别单击的项目的标记。
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
<ul>
@foreach (var flag in item.Flags)
{
<li>
@Html.DisplayFor(modelItem => flag.Name) |
@(flag.Enabled ? "Yes" : "No") |
@Html.ActionLink("Edit", "FlagEdit", new { flagId = flag.Id, itemId = item.Id })
</li>
}
</ul>
</td>
If this isn't clear, please ask and I'll elaborate. 如果不清楚,请询问,我会详细说明。 I'm trying to send the itemId but because I am within the flags foreach, I cannot get hold of it. 我正在尝试发送itemId,但是因为我在foreach标记之内,所以无法获取它。
when I get to the first if that checks params are not null, the check fails. 当我到达第一个,如果检查参数不为null时,检查将失败。
[ActionName("FlagEdit")]
public async Task<ActionResult> EditFlagAsync(string flagId, string itemId)
{
if (flagId == null || itemId == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Item item = await DocDBRepo<Item>.GetItem(itemId);
if (item == null)
{
return HttpNotFound();
}
//do update
return View(item);
}
I've tried searching but maybe I'm just not searching the right keywords. 我曾尝试搜索,但也许我只是没有搜索正确的关键字。 Can anyone please help? 谁能帮忙吗?
尝试这个:
@Html.ActionLink("Edit", "FlagEdit", new { flagId = flag.Id, itemId = item.Id }, null)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.