Search code examples
compiler-errorsblazor-server-side.net-8.0quickgrid

Blazor QuickGrid TemplateColumn is giving a compile error


I am newbie with QuickGrid and .Net-8.
I get this error for the Blazor QuickGrid .net-8.

Error (active) CS1061 'DateTime?' does not contain a definition for 'Year' and no accessible extension method 'Year' accepting a first argument of type 'DateTime?' could be found (are you missing a using directive or an assembly reference?)

I really don't understand the error text, and don't know how to fix this error. Can this be fixed? Thanks.

The QuickGrid works perfectly for the PropertyColumns. However, the above error appears during compilation for the TemplateColumn shown below.

<PropertyColumn Property="f => f.DT_END"   Format="MM/dd/yyyy" Title="End Date" Sortable="false"/>
<TemplateColumn>
   <div>
      <span>@(_FilteredVehicles.First(r => r.UID_VEHICLE == context.UID_VEHICLE).DT_END!.Year.ToString())</span>
   </div>
</TemplateColumn>

// ////////////////////////////////////////////////////////////

After the above compilation error no longer appears, thanks to @MisterMagoo, I now get this error that I do not understand.

Error (active) RZ9999 The child content element 'ChildContent' of component 'TemplateColumn' uses the same parameter name ('context') as enclosing child content element 'ChildContent' of component 'AuthorizeView'. Specify the parameter name like: ' to resolve the ambiguity


Solution

  • Regarding the second error...I found an SO answer that points out the solution -- to rename the 'context" of the 'AuthorizeView' to

    <AuthorizeView Roles="FCI, Admin,Manager" Context="authContext">
    

    Hope this SO solution helps.

    Component 'EditForm' uses the same parameter name ('context') as enclosing child content element 'Authorized'