1

Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions.

I had search through google, and cant see to find better way to solve this, I want to do a check if the data exist in table, then set to true, else set to false, is there anywhere to make it work? If there is no way to use linq to make it work, what I can think of is to use jquery ajax to populate the table

<tbody>
       @foreach (var item in (ViewData["menu"] as IEnumerable<overview>))
       {
           <tr>
           <td>@Html.CheckBoxFor(model=>model.AccessRights.Where(m=> m.mcd ==item.mcd && m.ise=="Y").Any())
           </tr>
       }
</tbody>
Se0ng11
  • 2,303
  • 2
  • 26
  • 45

1 Answers1

3

Change your overview ViewModel to include for example:

public bool AccessRightsExist {get;set;}

then in your controller you set it:

overviewModel.AccessRightsExist = dbContext.AccessRights.Where(m=> m.ise=="Y").Any();

and last, your view would then be:

<td>@Html.CheckBoxFor(model=>item.AccessRightsExist)</td>

If you don't have a ViewModel, add one to your solution.

PostureOfLearning
  • 3,481
  • 3
  • 27
  • 44