如何使用设置显示/隐藏视图中的内容

时间:2015-11-30 09:40:53

标签: c# asp.net-mvc

在我的MVC 5应用程序中,我有一张带有局部视图的物品卡。根据设置(存储在我的设置表中),我想显示/隐藏特定列。

设置表:

  • Id = 1 | Group = ItemCard | Key = ShowStockValue |值= 0
  • Id = 2 | Group = OtherGroup | Key = SomeKey | Value = SomeValue

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

但我不知道这是不是要走了?

0 个答案:

没有答案