Query returns no results - how to add custom message?

Topics: Customizing Orchard, General
Jun 3, 2013 at 11:34 AM
Edited Jun 5, 2013 at 8:46 PM
Hi
I have a projection working from a menu bar to display properties.
Please can you tell me how to add a custom message to be displayed when no results are returned?

Many thanks
Kirsty
Jun 4, 2013 at 9:28 AM
Edited Jun 5, 2013 at 8:45 PM
Can anyone help with this please?
Jun 9, 2013 at 11:58 PM
You could create a view using one of the alternates for the List shape (assuming you're rendering the projection using the ListLayout) and add logic there to determine whether to render the list or the "no results" message.
Jun 10, 2013 at 10:04 AM
Edited Jun 13, 2013 at 1:02 PM
OK I am still stuck on this :(
I have created an alternate view of the list projection page. Them I have tried adding variations of the following

@if(@Model.ContentItem.Property.Value = 0) {
      <div class="propertycontent">
        @Display(Model.Content)
       </div>
 }
else
{
<p> There are no results to display </p> }

I keeps causing an error! I am not sure how to reference the value of my Property list. (Properties is the container).

Any ideas please?
Jun 18, 2013 at 1:14 PM
Please can someone help with this one? All I want to do is add an error message if there are no list items returned.

I am now using the alternate view Parts.Container.Contained-Properties.cshtml and am trying variations on the following but can't get any of them to work.

@if (Model.List.Property.Value.Count != 0)
{
@Display(Model.List)

@Display(Model.Pager)
}
else
{
<p>There are no results</p>
}

Please can anyone give me any ideas?

Thanks,
Kirsty
Jun 20, 2013 at 8:41 AM
Can anyone help with this please?
Coordinator
Jun 26, 2013 at 5:25 AM
When you say something like "keeps causing an error", it may help to say what error and to provide as many details as possible (stack trace, etc.). Otherwise, nobody can guess and help you.
Aug 12, 2013 at 12:23 PM
Hi there

I am still stuck on this one ........................

No error, I just get a blank page.

Can anyone tell me if @if (Model.List.Property.Value.Count != 0) is the correct syntax to use when trying to determine if my list has returned no results in a projection?

Thanks,

Kirsty
Aug 12, 2013 at 3:21 PM
Edited Aug 12, 2013 at 3:22 PM
Kirsty,

You don´t need to get the value from the List in the alternate view.
You can acomplish this in a much cleaner way, by using the placement.info and zones.
Here´s is the code i use for displaying a projection list of team members on a website i created:

Placement.info
  <Match ContentType="Team">
    <Match DisplayType="Detail">    
      <Place Parts_ProjectionPart_List="TeamZone"/>
    </Match>
  </Match>
The Projection Page Content Type Name is Team, the projection list is a list of team members, then i created an alternate for the Projection Page, called:

Content.Team.cshtml, in this view i created a zone called TeamZone, and before displaying it, i check if it´s null, if it is i render the message.

<div class ="grid_9 ">
@if (Model.TeamZone != null)
{
    @Display(Model.TeamZone)
}
else
{
    <span>There are no members yet.</span>
}
    
</div>
I believe the main point for you to understand here is the placement.info, there you can dispatch a part shape or field shape to a zone (it´s a shape as well, this is the beauty of orchard), and then check if it´s null or not, or render it wherever you want.
This way it´s also easyer for you to add other Themes to your website or even add other parts or fiels to your content types, because the values from them are not hardcoded in the views.
Here are some references you can read about placement.info:

http://docs.orchardproject.net/Documentation/Understanding-placement-info

Hope it helps.

Nuno.
Aug 12, 2013 at 3:44 PM
Edited Aug 12, 2013 at 3:47 PM
Kirsty,

Sorry i led you in to a mistake, checking if the zone is null, is not enough because it still renders the zone as an empty list, i tryied it in my code.
In order to solve i had to check for the list, and to do that you have to check the projection part here´s the altered code in Content.Team.cshtml view:
<div class ="grid_9 ">
@if (Model.ProjectionPart.List != null)
{
    @Display(Model.TeamZone)
}
else
{
    <span>There are no members yet.</span>
}
    
</div>
The rest of the code is valid and i believe is a best practice.

Nuno.
Aug 13, 2013 at 9:26 AM
Edited Aug 13, 2013 at 9:26 AM
Hi Nuno

thanks so much for both of your replies. I am looking into implementing my projections this way.

First of all, I am little confused and wondered if you could help? ................................

At the beginning part when you have the Match statement as
<Match ContentType="Team">
<Match DisplayType="Detail">    
  <Place Parts_ProjectionPart_List="TeamZone"/>
</Match>
</Match>

How do you set up Team - which you have described as a projection page content type. Can I use an existing projection page I have? (E.g. I have a projection page called results4) s results4 or do I need to set up a new content type and if so which properties does it need to have? Can I use an existing query I have for the part where you have named TeamZone?

Thanks so much in advance,
Kirsty
Aug 13, 2013 at 11:47 AM
Hi

I feel as though it may be beneficial for me to continue with displaying properties as I have been doing as I am half way there and my results page uses request querystrings from dropdowns to get there.


I have been trying to use the following code

x= @Model.Items.Count @if (Model.Items != null && Model.Items.Count != 0)
{
@Display(Model.List)

@Display(Model.Pager)
}

else
{
<div class="projection-none"> <p>No properties found with the specified criteria.</p> <p> <a href="#" class="backlink" onclick="history.back();">Back to property search</a></p> </div> }

I have put the x= @Model.Items.Count in to see how many properties are returned. This works and returns a number and if there are no properties returned, I get the error message.

The following code is not working though
@Display(Model.List)

@Display(Model.Pager)

Do I need different syntax? Its driving me crazy and the list results wont display.

Any help appreciated.

Thanks
Kirsty
Aug 13, 2013 at 12:16 PM
Hi kirstybash,

Here is how I have done it on my sites:
  1. Create / override the Parts.ProjectionPart.List.cshtml view
  2. Use the following code segment in this file:
@{
    List<Object> items = Model.Items;
}

@if (items.Count() > 0) {
    foreach(var item in items) {
        @Display(item)
    }

    if (Model.Pager != null) {
        @Display(Model.Pager)
    }
}
else {
    @T("Check back soon...")
}
Hope it works for you.
Aug 13, 2013 at 12:46 PM
kirstybash wrote:
Hi

I feel as though it may be beneficial for me to continue with displaying properties as I have been doing as I am half way there and my results page uses request querystrings from dropdowns to get there.


I have been trying to use the following code

x= @Model.Items.Count @if (Model.Items != null && Model.Items.Count != 0)
{
@Display(Model.List)

@Display(Model.Pager)
}

else
{
<div class="projection-none"> <p>No properties found with the specified criteria.</p> <p> <a href="#" class="backlink" onclick="history.back();">Back to property search</a></p> </div> }

I have put the x= @Model.Items.Count in to see how many properties are returned. This works and returns a number and if there are no properties returned, I get the error message.

The following code is not working though
@Display(Model.List)

@Display(Model.Pager)

Do I need different syntax? Its driving me crazy and the list results wont display.

Any help appreciated.

Thanks
Kirsty
Kirsty,

In the code i showed you i´m acessing the list in the model, you can do whatever you want with the list, count foreach etc.

@if (Model.ProjectionPart.List != null) // Here is the list
{
@Display(Model.TeamZone)
}
else
{
<span>There are no members yet.</span>
}

</div>

Nuno
Aug 13, 2013 at 12:56 PM
Edited Aug 13, 2013 at 12:58 PM
kirstybash wrote:
Hi Nuno

thanks so much for both of your replies. I am looking into implementing my projections this way.

First of all, I am little confused and wondered if you could help? ................................

At the beginning part when you have the Match statement as
<Match ContentType="Team">
<Match DisplayType="Detail">    
  <Place Parts_ProjectionPart_List="TeamZone"/>
</Match>
</Match>

How do you set up Team - which you have described as a projection page content type. Can I use an existing projection page I have? (E.g. I have a projection page called results4) s results4 or do I need to set up a new content type and if so which properties does it need to have? Can I use an existing query I have for the part where you have named TeamZone?

Thanks so much in advance,
Kirsty
Kirsty,

In my case I created a content type called Team and attached the projection part to it (because i have other parts), in your case if you are using the Projection content type builtin with orchard, you have to match it like this:

<Match ContentType="Projection">
 <Match DisplayType="Detail">    
   <Place Parts_ProjectionPart_List="TeamZone"/>
 </Match>
</Match>

The rest of the code remains the same, because the builtin Projection content Type has the projection part attached to it too.


Nuno.
Aug 13, 2013 at 1:17 PM
Thanks so much guys, this works brilliantly.

Using shape tracer I couldn't see an alternate called Parts.ProjectionPart.List.cshtml so I tried manually creating this and adding the code but this did not work.

I then tried creating the following alternate List-ProjectionPage.cshtml and added the following code in:-

@{
List<Object> items = Model.Items;
}

@if (items.Count() > 0) {
foreach(var item in items) {
    @Display(item)
}

if (Model.Pager != null) {
    @Display(Model.Pager)
}
}
else {
<div class="projection-none"> <p>No properties found with the specified criteria.</p> <p> <a href="#" class="backlink" onclick="history.back(); return false;">Back to property search</a></p> </div> }

It works a treat! Thanks both SO much, much appreciated!

Kirsty