Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用设置在视图中显示/隐藏内容_C#_Asp.net Mvc - Fatal编程技术网

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

C# 如何使用设置在视图中显示/隐藏内容,c#,asp.net-mvc,C#,Asp.net Mvc,在我的MVC5应用程序中,我有一个带有局部视图的项目卡。根据设置(存储在我的设置表中),我希望显示/隐藏特定列) 设置表: Id=1 | Group=ItemCard | Key=ShowStockValue | Value=0 Id=2 | Group=OtherGroup | Key=SomeKey | Value=SomeValue 等等 StockViewModel public class StockViewModel { public int Id { get; set;

在我的MVC5应用程序中,我有一个带有局部视图的项目卡。根据设置(存储在我的设置表中),我希望显示/隐藏特定列)

设置表:

  • Id=1 | Group=ItemCard | Key=ShowStockValue | Value=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);
}
在我的视图中,我想根据设置
ShowStockValue
隐藏列
StockValue
。我想在我的部分观点行动中加入这样的内容:

ViewBag.CardSettings = settingsRepo.GetSettingsByGroup("ItemGroup");
在我的视图中,通过设置循环

或者直接将设置放入ViewBag中,如
ViewBag.ShowStockValue


但我不知道这是否是一种方法?

如果要隐藏列,最好使用ViewBag.ShowStockValue。如果要隐藏列,最好使用ViewBag.ShowStockValue。