So a drop down is used to select the users name, then click ‘view’ and it will display all the holidays this user has previously booked.
From here the user can click ‘create new’ which will bring them to a create new page.
Instead of having to re-select their name from another drop down i carried across the currentuserID and replaced the second drop down with the users ID.
Everything was working fine with 2 separate drop downs, the user could book holidays etc…
However now (after I changed the second drop down to hold the ID value) I am getting an error from my listHoliday Method in my controller:
Error: InvalidOperationException was unhandled by the user code. Sequence contains no elements.
var dbPerson1 = (from p in db.People
where p.Id == PersonId
select p).Single();
Could anyone advise what to do?
it means the linq query you’re doing returns no results, to .Single() throws an exception.
try
dbPerson1will then be null if the query doesn’t return anything.hope that helps