开发者

Display custom text if asp.net mvc for each loop is empty

开发者 https://www.devze.com 2022-12-13 07:38 出处:网络
Still learning asp.net and mvc, please be gentle :) Currently setting up an MVC view to consume and display an RSS feed, using this method described on CodeProject.

Still learning asp.net and mvc, please be gentle :)

Currently setting up an MVC view to consume and display an RSS feed, using this method described on CodeProject.

What I want to do is when no items are returned for the RSS feed, display a custom piece of text, eg something like the following piece of psuedocode.

If ViewData.Model.Items is not empty
 Then run the for loop
 Else display "sorry, no items to display"
End If

I know how to do this from my classic ASP days if I was displaying records from a table, being:

If tablename.EOF And tablename.BOF Then...

But I don't have the first clue as to how this is acheived in .net, particually when the results are rendered using a for loop.

开发者_开发知识库If you can point me in the right direction of where I should be looking it would be greatly appreciated.


I usually do something stupidly simple like this

<%
if(Model.Items.Count >0){
   foreach(..)
}
else{
%>
    Sorry, no items to display
<%
}
%>

I guess the proper way would also be to put this in a html helper extension, but above works for me

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号