C# Razor template throws error when ListContent Title is null

141 views Asked by At

DNN 7.4.2 2SXC 8.8.0

Hey there,

Long time fan. The newest version is amazing. Everyone is loving the interface. :D

I'm wondering if you can help me with a problem I've struggled with for a while now. I don't think it's related to the module version but perhaps my C# template.

When I have a listing (like a Board of Directors, for example), whenever I add the first item, my c# razor template throws an error because I haven't defined @ListContent.Title yet. But I can't edit the title without adding multiple items first. So my problem (and my workaround) looks like this:

  1. I add the Content module to the page
  2. I select my Content Type (People) and my template (Board of Directors)
  3. It gives me the message that I have no demo item and then I click the blue edit pencil to start my first one
  4. Once I click the edit icon, the modal appears and I add my first person (board member) and click save.
  5. The module throws an error because the List Header Title has not been defined yet.
  6. I have to remove (or comment out) anything related to @ListContent in my template so that the error disappears.
  7. I then add a second item so that I can actually view the list and, in turn, get to List Header.
  8. I edit List Header to fill in the Title and save it.
  9. Then I go back to my template and put the @ListContent.Title and @ListContent.Toolbar portion back in and save.

It's a lot of roundabout steps and I'm wondering how can I avoid this issue? I've tried putting in conditional statements around the @ListContent.Title value (and other @ListContent values) but it doesn't fix the problem. I still have to completely remove it until it actually becomes a list (by adding at least a second item). This problem happens on all of my lists (templates with List Enabled).

Here is the error that appears:

There was an error while rendering the template: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot perform runtime binding on a null reference at CallSite.Target(Closure , CallSite , Object ) at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0) at CallSite.Target(Closure , CallSite , Object ) at ASP._Page_Portals_0_2sxc_Content__Board_of_Directors_cshtml.Execute() in d:\home\site\wwwroot\Portals\0\2sxc\Content\_Board of Directors.cshtml:line 9 at System.Web.WebPages.WebPageBase.ExecutePageHierarchy() at ...

I initially posted this in the issues on the codeplex site but I see that I should have added it here. You can download the attachment here: https://sexycontent.codeplex.com/workitem/1971

1

There are 1 answers

1
iJungleBoy On BEST ANSWER

You're making life too complicated :).

Basically each template can be configured to use a demo-item in the list-header, just like the demo-item in the normal list. This should provide the template with real data, even if no header was ever entered.

:)