Search code examples
c#razor

C# Razor asp.net Cannot invoke non-delegate type


I'm running into an error with my razor template that says: Error compiling Razor Template: Cannot invoke a non-delegate type (check logs for more details)

I've tried declaring the variables with @ and without @ in front both methods give the same error.

The looping portion at the bottom works fine it's just the singular non-looping dates at the top i'm having trouble with.

@{
var FDate1 = @AME.GridF18.FDate1("SubmissionID='" + TknParams.SubmissionID + "'");
var FDate2 = @AME.GridF18.FDate2("SubmissionID='" + TknParams.SubmissionID + "'");
var FDate3 = @AME.GridF18.FDate3("SubmissionID='" + TknParams.SubmissionID + "'");
var FDate4 = @AME.GridF18.FDate4("SubmissionID='" + TknParams.SubmissionID + "'");
var FDate5 = @AME.GridF18.FDate5("SubmissionID='" + TknParams.SubmissionID + "'");
var FDate6 = @AME.GridF18.FDate6("SubmissionID='" + TknParams.SubmissionID + "'");
var FDate7 = @AME.GridF18.FDate7("SubmissionID='" + TknParams.SubmissionID + "'");
}
<div class="table-responsive"> 
 <table class="table table-striped table-condensed table-bordered" width="100%" border="0">
  <tbody>
    <tr>
        <th colspan="7" scope="col">@FDate1</th>
        <th colspan="2" scope="col">@FDate2</th>
        <th colspan="2" scope="col">@FDate3</th>
        <th colspan="2" scope="col">@FDate4</th>
        <th colspan="2" scope="col">@FDate5</th>
        <th colspan="2" scope="col">@FDate6</th>
        <th colspan="1" scope="col">@FDate7</th>
    </tr>
    <tr>
      <th rowspan="2" scope="col">Project #</th>
      <th rowspan="2" scope="col">PW</th>
      <th rowspan="2" scope="col">Project Name</th>
      <th rowspan="2" scope="col">Type of Work</th>
      <th rowspan="2" scope="col">Mile</th>
      <th rowspan="2" scope="col">Toll</th>
      <th rowspan="2" scope="col">Park</th>
      <th colspan="2" scope="col">Monday</th>
      <th colspan="2" scope="col">Tuesday</th>
      <th colspan="2" scope="col">Wednesday</th>
      <th colspan="2" scope="col">Thursday</th>
      <th colspan="2" scope="col">Friday</th>
      <th scope="col">Saturday</th>
      <th scope="col">Sunday</th>
      <th scope="col">Total</th>
    </tr>
    <tr>
      <th scope="col">RT</th>
      <th scope="col">OT</th>
      <th scope="col">RT</th>
      <th scope="col">OT</th>
      <th scope="col">RT</th>
      <th scope="col">OT</th>
      <th scope="col">RT</th>
      <th scope="col">OT</th>
      <th scope="col">RT</th>
      <th scope="col">OT</th>
      <th scope="col">&nbsp;</th>
      <th scope="col">&nbsp;</th>
      <th scope="col">&nbsp;</th>
    </tr>
     @foreach (var row in AME.GridF18("SubmissionID='" + TknParams.SubmissionID + "'")) {
    <tr>
      <td>@row.ProjectNumber</td>
      <td><input id="checkBox" type="checkbox"></td>
      <td>@row.ProjectName</td>
      <td>@row.TypeofWork</td>
      <td>@row.Mile</td>
      <td>@row.Toll</td>
      <td>@row.Park</td>
      <td>@row.MonRT</td>
      <td>@row.MonOT</td>
      <td>@row.TuesRT</td>
      <td>@row.TuesOT</td>
      <td>@row.WedsRT</td>
      <td>@row.WedsOT</td>
      <td>@row.ThursRT</td>
      <td>@row.ThursOT</td>
      <td>@row.FriRT</td>
      <td>@row.FriOT</td>
      <td>@row.Saturday</td>
      <td>@row.Sunday</td>
      <td>@row.Total</td>
    </tr>
    }
  </tbody>
</table>
</div>

Solution

  • Error compiling Razor Template: Cannot invoke a non-delegate type

    Because of this statement

    @foreach (var row in AME.GridF18("SubmissionID='" + TknParams.SubmissionID + "'")) {
    

    Here the GridF18 is treated as delegate by the compiler which it is expecting to return an IEnumerable.

    It looks like you are trying to loop through a list of dates. You need to create a list then add those dates to the list and use that list in your loop as collection source