c# – 如何在Razor View中确定模型是否为空
发布时间:2020-12-15 18:32:49 所属栏目:百科 来源:网络整理
导读:@model IEnumerableFramely2011.Models.Frames@{ ViewBag.Title = "Index";}h2Index/h2p @Html.ActionLink("Create New","Create")/ptable tr th/th th PictureID /th th UserID /th /tr@foreach (var item in Model){ tr td @Html.ActionLink("Edit","Edit"
@model IEnumerable<Framely2011.Models.Frames> @{ ViewBag.Title = "Index"; } <h2>Index</h2> <p> @Html.ActionLink("Create New","Create") </p> <table> <tr> <th></th> <th> PictureID </th> <th> UserID </th> </tr> @foreach (var item in Model) { <tr> <td> @Html.ActionLink("Edit","Edit",new { /* id=item.PrimaryKey */ }) | @Html.ActionLink("Details","Details",new { /* id=item.PrimaryKey */ }) | @Html.ActionLink("Delete","Delete",new { /* id=item.PrimaryKey */ }) </td> <td> @item.PictureID </td> <td> @item.UserID </td> <td> Meta 1: @item.MetaTagsObj.Meta1 Meta 2: @item.MetaTagsObj.Meta2 Meta 3: @item.MetaTagsObj.Meta3 </td> </tr> } </table> 如果模型出现空白,我怎么才能让它打印出“没有框架”以便根本不打印任何html表格,我认为简单的if语句就足够了,但我是razor的新手我不确定如何做到这一点. 解决方法
将其添加到页面顶部:
@using System.Linq 然后用这个块替换你的代码. @if( !Model.Any() ) { <tr><td colspan="4">There are no Frames</td></tr> } else { foreach (var item in Model) { <tr> <td> @Html.ActionLink("Edit",new { /* id=item.PrimaryKey */ }) | @Html.ActionLink("Details",new { /* id=item.PrimaryKey */ }) | @Html.ActionLink("Delete",new { /* id=item.PrimaryKey */ }) </td> <td> @item.PictureID </td> <td> @item.UserID </td> <td> Meta 1: @item.MetaTagsObj.Meta1 Meta 2: @item.MetaTagsObj.Meta2 Meta 3: @item.MetaTagsObj.Meta3 </td> </tr> } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- 在PostgreSQL中将列数据类型从Text更改为Integer
- 避免连续的“如果让”声明在Swift
- c# – Automapper Custom Resolver – 将Reposit
- reactjs – 可能是使用Redux而不是Flux的缺点
- 什么是Ruby on Rails的一个很好的PDF到HTML转换器
- ios – 在Xcode 4.3/4.3.1中,任何使“验证项目设
- postgresql – Postregsql日期差异基于秒
- ruby-on-rails – Rails:Rake测试:功能无法访问
- ruby-on-rails – 嵌套模型,表单和date_select F
- swift – 如何设置单元格间距和UICollectionView
热点阅读