Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9017953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:23:56+00:00 2026-06-16T04:23:56+00:00

So a drop down is used to select the users name, then click ‘view’

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T04:23:57+00:00Added an answer on June 16, 2026 at 4:23 am

    it means the linq query you’re doing returns no results, to .Single() throws an exception.

    try

    var dbPerson1 = (from p in db.People
                             where p.Id == PersonId
                             select p).FirstOrDefault(); // or use SingleOrDefault() if People are unique
    
    if (dbPerson1==null) 
    {
        throw new HolidayAllocationException("Person not found");
    }
    else
    {
        // person found
        if (dbPerson.HolidaysRemaining > 0) 
        {
            AllocateHoliday(); // or whatever you need to do
        }
        else 
        {
            throw new NoHolidayLeftException(); 
        }
     }
    

    dbPerson1 will then be null if the query doesn’t return anything.

    hope that helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create custom drop-down select like the one used on twitter when
I have used the rails will paginate gem for pagination.I have a drop down
I have the following code - it is used to load a drop down
I have a View Feedback page with two drop down lists to filter the
I have a drop down menu that the user can select a location from.
I've got a number of drop down lists, which allow the user to select
drop down value not appearing for second list , tried everything .When user selects
I have one drop down list in my page, which contains two options. What
I created a PHP Drop Down which is populated from a MySql Database and
I have a drop down menu which you can see here on jsfiddle .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.