zoukankan      html  css  js  c++  java
  • MVC ---- IEnumerable<T>、List<T> 前台遍历展示

    突然做前台数据展示,发现IEnumerable 对一个列表的展示还是可以,但要是多个类型放在一个表中如何处理呢,如下:

     一个类IEnumerable遍历

    后台

      
     public IEnumerable<NewsEntity> GetNotice()
     {
           int type = 1;
           return noticeBLL.GetListByType(type);
     }

    前台:

    引用
    @model IEnumerable<LeaRun.Application.Entity.PublicInfoManage.NewsEntity>
    <div class="panel-body">
       <ul>
         @foreach (var item in Model)
          {
              <li><a href="#">@item.FullHead</a><span class="time">@item.CreateDate.ToString().Split(' ')[0].Replace("/", "-")</span></li>
          } 
        </ul>
    </div>

      

    多个类型放在同一个表中处理方式

        首先在control中建一个临时类

       /// <summary> /// 公告实体封装 /// </summary> public class GetIEnumerable { /// <summary> /// 公告 /// </summary> public IEnumerable<NewsEntity> Notice { get; set; } /// <summary> /// 新闻 /// </summary> public IEnumerable<NewsEntity> News { get; set; } }

    用法:

        public GetIEnumerable GetNotice()
            {
                GetIEnumerable ge = new GetIEnumerable();
                int type = 2;//2、公告
                ge.Notice = noticeBLL.GetListByType(type);
    
                type = 1;    //1、新闻
                ge.News = noticeBLL.GetListByType(type);
                return ge;
            }
    
        //网页面上跳转
         public ActionResult AdminLTEDesktop()
            {
                return View(GetNotice());
            }

    页面:

    引用
    @model LeaRun.Application.Web.Controllers.GetIEnumerable
    <div class="panel-body">
       <ul>
            @foreach (var item in Model.News)
            {
                <li><a href="#">@item.FullHead</a><span class="time">@item.CreateDate.ToString().Split(' ')[0].Replace("/","-")</span></li>
            } 
        </ul>
    </div>
    
     <div class="panel-body">
        <ul>
            @foreach (var item in Model.Notice)
            {
                <li><a href="#">@item.FullHead</a><span class="time">@item.CreateDate.ToString().Split(' ')[0].Replace("/", "-")</span></li>
            } 
        </ul>
     </div>

     ======================================================================================================

    List<T> 页面遍历

    引用命名空间

    @using System.Data;
    @using NFine.Domain._03_Entity.POCO.Business;
    @model List<NFine.Domain._03_Entity.POCO.Business.CustomerAndFollow>
      @{ foreach (CustomerAndFollow activities in Model)
             {
                <table class="ui-jqgrid-btable ui-common-table table table-bordered" style=" background:#ffffff!important; margin-bottom:30px;">
                    <tbody>
                        <tr class="jqgfirstrow">
                            <td style="height:50px;line-height:50px;">@activities.CustomerId</td>
                            <td style="height:50px;line-height:50px;">@activities.F_FullName</td>
                            <td style="height:50px;line-height:50px;">@activities.F_Msisdn</td>
                            <td style="height:50px;line-height:50px;">@activities.F_CreatorTime</td>
                            <td style="height:50px;line-height:50px;">@activities.F_CreatorUserName</td>
                        </tr>
                        <tr>
                            <td colspan="5">
                                <textarea id="@activities.FollowId" class="ckeditor">@activities.F_Description</textarea>
                            </td>
                        </tr>
                    </tbody>
                </table>
             }}

    后台:

        public override ActionResult Index()
            {
                int record = 0;
                Pagination page = new Pagination();
                page.rows = 1;
                page.page = 2;
                page.records = record;
                List<CustomerAndFollow> follow = custapp.GetFollowList(page, out record);
                return View(follow);
            }
  • 相关阅读:
    开发一个cube.js cratedb driver
    dremio 时间操作函数
    authelia web sso 解决方案
    dremio sql server 出现无法绑定由多个部分组成的标识符的解决方法
    cratedb 4.5 企业特性可以免费使用了
    cube.js 新版本cubestore 禁用
    spring-native 编译spring 应用为graalvm native 镜像
    streamsets tar 模式启动
    streamset data collector 新注册机制
    Swarm 集群管理
  • 原文地址:https://www.cnblogs.com/youmingkuang/p/6474805.html
Copyright © 2011-2022 走看看