0
我有如下的主視圖:局部視圖之間Asp.Net的mvc傳遞參數
<div class="wellContainer" id="stockCardGroupContainer">
@Html.Action("_StockGroupMenu", new { stockGroupId = 1})
</div>
<div id="stockCardContainer" class="wellContainer">
@Html.Action("_Index", "WrhStockCard", new { stockGroupId = ViewBag.wrhRelatedStockGroupId })
</div>
這裏是返回部分視圖的方法。
public PartialViewResult _StockGroupMenu(int? id)
{
var wrhStockGroup = db.WrhStockGroup.Include(w => w.RelatedWrhStockGroup).Where(p => p.RelatedWrhStockGroupId == id);
ViewBag.wrhRelatedStockGroupId = id;
ViewBag.stockGroupName = db.WrhStockGroup.Find(id).Name;
return PartialView(wrhStockGroup.ToList());
}
public PartialViewResult _Index(int? stockGroupId)
{
var relatedStockCards = stockCardService.GetStockCardsByGroupId(stockGroupId);
ViewBag.stockGroupId = stockGroupId;
ViewBag.stockGroupName = db.WrhStockGroup.Find(stockGroupId).Name;
return PartialView(relatedStockCards);
}
的情況是,當用戶單擊一個組,我需要顯示股票卡「stockCardContainer」,也顯示出,在stockCardGroupContainer相關childGroupd。但我在_StockGroupMenu方法中設置ViewBag.wrhRelatedStockGroupId,但不能將它傳遞給第二個@ Html.Action,因爲它是不同的局部視圖。