ASP.NET MVC - 当模型不可用时隐藏面板
我有标准的搜索场景:用户输入搜索参数并单击搜索按钮 - 结果显示在下面的面板中。我想要做的是根据搜索结果是否可用来控制面板的可见性。我尝试按如下方式对面板进行编码,但在运行时出现解析错误。
<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.
如何根据模型的可用性切换面板?
I have the standard search scenario: user enters search parameters and clicks the search button - results show up in the panel below. What I want to do is to control the visibility of the panel based on whether search results are available or not. I have tried to code my panel as follows, but I am getting a parse error at run time.
<asp:Panel ID="ResponsePanel" Visible="<%= Model != null %>" runat="server">
...
</asp:Panel>
The parse error I am getting is this:
Cannot create an object of type 'System.Boolean' from its string representation
'<%= Model != null %>' for the 'Visible' property.
How do I toggle the panel depending on the availability of the model?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如我在评论中所说,您不应该在 ASP.NET 应用程序中使用
。相反,构建一个部分视图(ascx)
然后在您的部分视图中,您可以放置您想要在模型为空时显示的所有“内容”。
您可以将部分内容放在两个位置之一。如果是共享的,则将其放入
Views/Shared
文件夹中。如果它特定于控制器,则将其放入Views/[ControllerName]
文件夹中。注意:请原谅我的 C#...我不是那么好。
As I said in my comment, you should not be using a
<asp:panel>
in your asp.net application.Instead, build a partial view (ascx)
Then in your Partial view, you can put all the "stuff" that you want to show if the Model is empty.
You can put the partial in one of two places. If it's shared, you put it in the
Views/Shared
folder. If it's specific to the Controller, you put it in theViews/[ControllerName]
folder.note: please forgive my C#... I'm not all that good.