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? Im lost thanks for any replies.
First, make sure the proper set of ID values is actually being bound to the drop-down. Secondly, the "Single()" method will throw that exception if the query does not return any results. If it's possible that the "p.Id == PersonId" condition could yield ZERO results, use "SingleOrDefault()" instead, which will assign a null value to dbPerson1 if nothing is found with the query.
I'd say debug with a breakpoint and verify that, for one, the drop-down has the correct ID's assigned to it, and also that "PersonId" is capturing the correct value. Also, make sure that the "PersonId" does in fact exist in the "People" table.
djj55: Nice but may have a permission problem Pete O'Hanlon: He has my permission to run it.