asp.net-mvc - 在 ASP.NET MVC 中隐藏表格或网格并显示 "No records found"消息

标签 asp.net-mvc html-helper

隐藏自定义网格、表格或 div 并在没有记录时显示“未找到记录”消息的最佳做法是什么。

这个想法是我想出来的。

<div class="<%= Html.IsVisible(Model.Count)">
    ...
    ..
    ..
</div>   

.displayNone {display:none;} .displayInherit {display:inherit;}

public static string IsVisible(this HtmlHelper helper,int recordCount)
{
     return recordCount == 0 ? "displayNone" : "displayInherit";
}

最佳答案

你的解决方案可以正常工作,但我认为你可能想得太多了:)

这会工作得很好:

<% if (Model.Count == 0) { %>
    No Records Found
<% } else { %>
    // do something to show the Model information here
<% }

关于asp.net-mvc - 在 ASP.NET MVC 中隐藏表格或网格并显示 "No records found"消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2077233/

相关文章:

asp.net - ASP.NET MVC 页面中没有 Intellisense 的 Visual Studio 2015 编辑器异常

c# - ASP.NET 5 中 System.Web.Mvc.Html.InputExtensions 的等价物是什么?

html - 如何设置 html.textboxfor 的宽度?

c# - 在静态类上调用重载的泛型方法

asp.net-mvc - "upstream prematurely closed connection while reading response header from upstream"在 Ubuntu MVC4 应用程序上使用 nginx、PostgreSQL 和 Mono

c# - 是否有将模型转换为 View 模型的快捷方式?

c# - 我无法访问我的 ApiController

html - 样式生成的表格行

model-view-controller - 确定号召性用语是否来自 View

asp.net-mvc - HtmlHelper 获取路由名称