如何在单击按钮时将循环值(viewbag值)传递到控制器中。 我对每个循环都有一个视图,并且我通过一个视图包获取循环的值。 现在我想要的是在单击按钮时将值(@ obj.Id)传递给ActionMethod(singleProduct) 这是我尝试的代码。
我的观看
@foreach (var obj in ViewBag.products1)
{
<div class="product_title">
<a href="single-product.html">@obj.ProductName</a>
</div>
<a href="single-product.html">
<img src=@Url.Content( @obj.ImageUrl) class="img-responsive" width="200" height="200" />
</a>
<li class="li_product_price">
<span class="old_price1"> @obj.ActualPrice</span>
<span class="new_price1"> @obj.OfferPrice</span>
<span class="saving1"></span>
</li>
<li class="li_product_desc">
<div class="caption">
<p>
@obj.ShortDesc
@obj.Id
</p>
</div>
</li>
<li class="li_product_buy_button">
<a class="btn btn-default" href="@Url.Action("SingleProduct", "Home")" role="button" name = "rowid" value ="@obj.Id">
</a>
</li>
}
我的控制器
public ActionResult SingleProduct(string rowid)
{
return View();
}