MVC ---- IEnumerable<T>、List<T> 前台遍历展示
突然做前台数据展示,发现IEnumerable 对一个列表的展示还是可以,但要是多个类型放在一个表中如何处理呢,如下:
一个类IEnumerable遍历
后台
public IEnumerable<NewsEntity> GetNotice()
{
int type = ;
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(' ')[].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、公告
ge.Notice = noticeBLL.GetListByType(type); type = ; //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(' ')[].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(' ')[].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="">
<textarea id="@activities.FollowId" class="ckeditor">@activities.F_Description</textarea>
</td>
</tr>
</tbody>
</table>
}}
后台:
public override ActionResult Index()
{
int record = ;
Pagination page = new Pagination();
page.rows = ;
page.page = ;
page.records = record;
List<CustomerAndFollow> follow = custapp.GetFollowList(page, out record);
return View(follow);
}
MVC ---- IEnumerable<T>、List<T> 前台遍历展示的更多相关文章
- MVC 从后台页面 取前台页面传递过来的值的几种取法
MVC 从后台页面 取前台页面传递过来的值的几种取法 <1>前台页面 Index视图 注意:用户名表单的name值为txtName 密码表单的name值为txtPassword & ...
- jquery之遍历展示title
//遍历展示title {field:'couponsList',title:'优惠劵类型',width:250,align:'center',sortable:true, formatter:fun ...
- bug解决思路——插入数据时,前台不展示数据
积攒一下平时解决bug时的思路,以后若是一头乱麻时翻出来看看~ 一个bug五一之前就和现场在定位,直到今天才算是定位到问题. 所有bug,还是得重现出来才可以发现问题.现场说登记记录时数据没在前台展示 ...
- springboot+thymeleaf中前台页面展示中、将不同的数字替换成不同的字符串。使用条件运算符
主要用到的知识就是thyme leaf中的条件运算符 表达式:(condition)?:then:else 当条件condition成立时返回then.否则返回else 具体代码:<td th: ...
- MVC 后台DataTable 前台遍历
/// <summary> /// 多级审批流展示 /// </summary> /// <returns></returns> public Acti ...
- Asp.Net MVC WebAPI的创建与前台Jquery ajax后台HttpClient调用详解
1.什么是WebApi,它有什么用途? Web API是一个比较宽泛的概念.这里我们提到Web API特指ASP.NET MVC Web API.在新出的MVC中,增加了WebAPI,用于提供REST ...
- 在ASP.NET MVC中使用Boostrap实现产品的展示、查询、排序、分页
在产品展示中,通常涉及产品的展示方式.查询.排序.分页,本篇就在ASP.NET MVC下,使用Boostrap来实现. 源码放在了GitHub: https://github.com/darrenji ...
- c# table 怎么在前台循环展示 ViewBag
后台 public ActionResult DoctorEvaluation()//前台页面 { HE_Department HE_dt = new HE_Department(); DataTab ...
- .Net MVC生成二维码并前端展示
简介: 二维码又称二维条码,常见的二维码为QR Code,QR全称Quick Response,是一个近几年来移动设备上超流行的一种编码方式,它比传统的Bar Code条形码能存更多的信息,也能表示更 ...
随机推荐
- awesome go library 库,推荐使用的golang库
https://github.com/avelino/awesome-go https://github.com/spf13/cobra # A Comm ...
- R中基本函数学习[转载]
转自:https://www.douban.com/note/511740050/ 1.数据管理 numeric:数值型向量 logical:逻辑型向量 character:字符型向量list:列表 ...
- PAT 1024 Palindromic Number[难]
A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...
- [LeetCode] 728. Self Dividing Numbers_Easy tag: Math
A self-dividing number is a number that is divisible by every digit it contains. For example, 128 is ...
- Mysql的group by语句
如上图查询结果,因为group by后面的字段是的分组的依据字段,所以select子句中只有是group by后面的字段,或者是聚集函数才有意义.然而mysql居然可以在select子句中出现不在gr ...
- python 读不同编码的文本,传递一个可选的encoding 参数给open() 函数
文件的读写操作默认使用系统编码,可以通过调用sys.getdefaultencoding() 来得到.在大多数机器上面都是utf-8 编码.如果你已经知道你要读写的文本是其他编码方式,那么可以通过传递 ...
- python管道pipe,两个进程,使用管道的两端分别执行写文件动作,带锁(lock)
#coding=utf-8import multiprocessing as mp def write_file(content,lock): lock.acquire() with op ...
- thinkphp相关
thinkphp相关1.thinkphp调试sql方法:echo M("table_name")->getLastSql(); 2. 条件查询设置多个条件参数的写法:(1). ...
- QEvent postEvent/sendEvent
可以自訂事件類型,最簡單的方式,是透過QEvent::Type指定事件類型的常數值,在建構QCustomEvent時作為建構引數並透過postEvent()傳送事件,例如: const QEvent: ...
- Web API设计方法论--比较完整的web api 开发过程
为Web设计.实现和维护API不仅仅是一项挑战:对很多公司来说,这是一项势在必行的任务.本系列将带领读者走过一段旅程,从为API确定业务用例到设计方法论,解决实现难题,并从长远的角度看待在Web上维护 ...