在我的MVC 5应用程序中,我有一张带有局部视图的物品卡。根据设置(存储在我的设置表中),我想显示/隐藏特定列。
设置表:
StockViewModel
public class StockViewModel
{
public int Id { get; set; }
public string Warehouse { get; set; }
public string Location { get; set; }
public string StockValue { get; set; }
}
控制器(部分查看操作):
public PartialViewResult PartialViewItemStock(int? id)
{
DateTime currentDate = DateTime.Now;
ItemStockRepository itemStockRepo = new ItemStockRepository();
WarehouseRepository warehouseRepo = new WarehouseRepository();
var warehouses = warehouseRepo.GetWarehousesPerItemId(id.Value);
var stock = itemStockRepo.GetStockPositionsPerWarehouse(id.Value, warehouses, currentDate).ToList();
return PartialView("_PartialViewItemStock", stock);
}
在我的视图中,我想根据设置StockValue
隐藏列ShowStockValue
。我想在我的部分视图操作中添加这样的东西:
ViewBag.CardSettings = settingsRepo.GetSettingsByGroup("ItemGroup");
在我的视图中循环设置
或直接将设置放在ViewBag中,如ViewBag.ShowStockValue
但我不知道这是不是要走了?