jeudi 23 juillet 2015

Operator '==' cannot be applied to operands of type int and 'Model'

I know this error is on here a few times but I cannot find a solution to my particular problem.

I have a table with a foreach loop which populates the table data as you can see below, also this table has an expand/close capability, within this i want to display all the groups in there relevant sections. The Error Operator '==' cannot be applied to operands of type 'int' and 'GroupSection' is appearing in the line:

if (item.SectionID == item.GroupSectionID)

I want to make sure that the groups details can only appear if its GroupSectionID is the same as the SectionID in that particular loop

Table

<table class="table table-striped">
    <!-- Render the table headers. -->
    <thead>
        <tr>
            <th class="col-md-1">+</th>
            <th class="col-md-2">Section ID</th>
            <th class="col-md-3">Section Name</th>

        </tr>
    </thead>
    <tbody>
        <!-- Render the details of each employee. -->
        @foreach (var item in Model)
        {
            <tr>
                <td class="col-md-1">+</td>
                <td class="col-md-2">@Html.DisplayFor(model => item.SectionID)</td>
                <td class="col-md-3">@Html.DisplayFor(model => item.SectionName)</td>
            </tr>

            if (item.SectionID == item.GroupSectionID)
            {
            <tr>
                <td class="col-md-1" colspan="3">@Html.DisplayFor(model => item.GroupID)</td>
                <td class="col-md-2" colspan="3">@Html.DisplayFor(model => item.GroupName)</td>
            </tr>
            }
        }
     </tbody>
</table>

Model

public class SectionDetail
{
    public int SectionID { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
    public GroupDetail GroupID { get; set; }
    public GroupDetail GroupName { get; set; }
    public GroupDetail GroupSectionID { get; set; }

}

public class GroupDetail
{
    public int GroupID { get; set; }
    public string GroupDescription { get; set; }
    public string GroupName { get; set; }
    public int GroupSectionID { get; set; }
    public string SectionName { get; set; }
}

Thanks in advance and I am relatively new to Stack so if you need and more information etc. please let me know

Aucun commentaire:

Enregistrer un commentaire