代码之家  ›  专栏  ›  技术社区  ›  Naresh

ASP.NET MVC-当模型不可用时隐藏面板

  •  0
  • Naresh  · 技术社区  · 15 年前

    我有一个标准的搜索场景:用户输入搜索参数并单击搜索按钮-结果显示在下面的面板中。我要做的是根据搜索结果是否可用来控制面板的可见性。我尝试按如下方式对面板进行编码,但在运行时会遇到一个分析错误。

    <asp:Panel ID="ResponsePanel" Visible="<%= Model != null %>" runat="server">
        ...
    </asp:Panel>
    

    我得到的分析错误是:

    Cannot create an object of type 'System.Boolean' from its string representation
    '<%= Model != null %>' for the 'Visible' property.
    

    如何根据模型的可用性切换面板?

    1 回复  |  直到 15 年前
        1
  •  3
  •   Chase Florell    15 年前

    <asp:panel>

    <% if(! Model.HasValue){ %>
        <%: Html.Partial("WhatWouldGoInYourPanel") %>
    <% } %>
    

    Views/Shared Views/[ControllerName]

    推荐文章