I’ve a table with contacts, a table with events, and a table that links contacts to those events.
So, in my view, I select an event and I can see a list of contacts that are allowed to be add to this event.
For the moment, it is possible to add a contact many times to an event.
I’d like to check if the contact is already add to the event before to display the button.
Here is my view :
<td>
@Code
Dim flag1 As Integer = 0
flag1 = (From a In Model.trans_Event
Where a.FK_id_contact = item.idContact And a.FK_id_Event = idEvent
Select a.idtrans).Count()
End Code
@If flag1 = 0 Then
<input type="button" value="add" />
Else
<input type="button" value="delete" />
End If
</td>
This code like that doesn’t work, and I don’t really see how I can check whether the contact has already been add or not. Here is the error I get :
Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: source
at this code ( if you havent made a copy/paste mistake )
you are trying to get a -> FK -> id_event and since there is no FK object in your model it breaks down to null exception.
looking at your code that should be “a.FK_id_Event”
Edit:
when filtering the collections in the model i would prefer;