C# 如何使用设置在视图中显示/隐藏内容
在我的MVC5应用程序中,我有一个带有局部视图的项目卡。根据设置(存储在我的设置表中),我希望显示/隐藏特定列) 设置表: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;
- Id=1 | Group=ItemCard | Key=ShowStockValue | Value=0
- Id=2 | Group=OtherGroup | Key=SomeKey | Value=SomeValue
- 等等
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。