c# - 创建灵活的模型
问题描述
在我的 WebApp 中,我使用了一个 wcf Web 服务,在我的示例中,我使用了一个返回超过 400 个值类型的方法。首先,WebApp 将在 View(Table) 中显示两列
//Model
public class OrdersviewModel
{
public int Articlenr { get; set; }
public string ArticleName { get; set; }
}
后来用户有可能添加或显示新列值,问题是模型如何?
解决方案
那是你的模型:
public class MyViewModel
{
public Dictionary<int, string> OrdersViewDictionary { get; set; }
}
进入视图,您可以使用这样的字典
@model MyViewModel
<table class="table-bordered">
<thead>
<tr>
<th>Index key</th>
<th>Value</th>
</tr>
</thead>
<tbody>
@foreach (var pairData in Model.OrdersViewDictionary) {
<tr>
<td>@pairData.Key</th>
<td>@pairData.Value</th>
</tr>
}
</tbody>
</table>
推荐阅读
- angularjs - ngtable 外部数据排序、过滤和分页不起作用
- postgresql - 在 linux os 上使用 postgresql 在 opmanager 中重置密码
- javascript - 添加显示更多显示更少按钮
- loops - 在 svg.js 中循环
- java - 在 ArrayList 中创建重复项的列表
- java - 如何在 Java 中的特定给定超时(5 秒)内停止方法执行?
- python-2.7 - TypeError:generate() 只需要 1 个参数(给定 5 个)
- wso2 - 我如何向 inputHandler 提供输入数据
- cmake - 为什么我需要可分离编译?
- javascript - 将图像 URL 转换为文件 - Javascript