c# - Operator '==' cannot be applied to operands of type int and 'Model' -
i know error on here few times cannot find solution particular problem.
i have table foreach loop
populates table data can see below, table has expand/close capability, within want display groups in there relevant sections. error operator '==' cannot applied operands of type 'int' , 'groupsection'
appearing in line:
if (item.sectionid == item.groupsectionid)
i want make sure groups details can appear if groupsectionid same sectionid in particular loop
table
<table class="table table-striped"> <!-- render 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 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 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 , relatively new stack if need , more information etc. please let me know
you're comparing int
complex type groupdetail
.
if (item.sectionid == item.groupsectionid.groupsectionid)
i think you're looking groupsectionid
property inside of groupdetail
class.
to prevent future confusion:
i suggest removing id
suffix properties references other classes. way won't mistake int
again :)
Comments
Post a Comment