ASP.Net MVC模型作为视图中的字典 [英] ASP.Net MVC model as dictionary in view

查看:164
本文介绍了ASP.Net MVC模型作为视图中的字典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  @model Dictionary< string,List< string>> 
< table width =60%>
< tr class =ui-widget-header>
< td>
___Category___
< / td>
< td>
___Detail___
< / td>
< / tr>

< tr>
< td>
@ Model.Key
< / td>
< td>
@ Model.Count
< / td>
< / tr>
< / table>

我该怎么做?



这是我的剃刀语法。



请帮助我。

解决方案

p>是的,你可以做到以下是样本

  @model Dictionary< string,List< string>> 

@foreach(KeyValuePair< string,List< string>对在模型中)
{
< label> @ pair.Key< /标签>
< div>
@foreach(@ pair.Value中的字符串数据)
{
< span> @data< / span>
}
< / div>

}


I would like to take the model as in view?

   @model Dictionary<string,List<string>>
        <table width="60%">
                <tr class="ui-widget-header">
                    <td>
                        ___Category___
                    </td>
                    <td>
                        ___Detail___
                    </td>
                </tr>

                <tr>
                    <td>
                         @Model.Key
                     </td>
                     <td>
                         @Model.Count
                     </td>
                 </tr>
             </table>

How could I do this?

here is my view with razor syntax.

Please help me.

解决方案

Yes you can do it. Below is the sample

@model Dictionary<string,List<string>>

@foreach (KeyValuePair<string, List<string>> pair in Model)
{
  <label> @pair.Key</label>
  <div>
    @foreach(string data in @pair.Value)
     {
      <span>@data </span>
     }
  </div>

}

这篇关于ASP.Net MVC模型作为视图中的字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆