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

  • Home
  • SEARCH
  • 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 1021907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:22:57+00:00 2026-05-16T11:22:57+00:00

I’m having problems with the helper Html.ListBoxFor(). Here is my ViewModel: public class NewReservation

  • 0

I’m having problems with the helper Html.ListBoxFor().

Here is my ViewModel:

public class NewReservation
{
    public SelectList AvailableServiceDates { get; set; }
    public DateTime SelectedServiceDate { get; set; }
}

Here is my action method:

    public virtual ActionResult New()
    {
        NewReservation newReservation = new NewReservation();
        newReservation.AvailableServiceDates = new SelectList(nhSession.Linq<Service>().Select(x => x.DateTime).Distinct());
        return View(newReservation);
    }

And in my view:

<%:Html.ListBoxFor(x => x.SelectedServiceDate, Model.AvailableServiceDates) %>

Here is the exception:

Value cannot be null. Parameter name:
source

Stack Trace:

[ArgumentNullException: Value cannot
be null. Parameter name: source]
System.Linq.Enumerable.Cast(IEnumerable
source) +4177011
System.Web.Mvc.Html.SelectExtensions.SelectInternal(HtmlHelper
htmlHelper, String optionLabel, String
name, IEnumerable1 selectList,
Boolean allowMultiple, IDictionary
2
htmlAttributes) +723
System.Web.Mvc.Html.SelectExtensions.ListBoxHelper(HtmlHelper
htmlHelper, String name, IEnumerable1
selectList, IDictionary
2
htmlAttributes) +47
System.Web.Mvc.Html.SelectExtensions.ListBoxFor(HtmlHelper1
htmlHelper, Expression
1 expression,
IEnumerable1 selectList,
IDictionary
2 htmlAttributes) +113
System.Web.Mvc.Html.SelectExtensions.ListBoxFor(HtmlHelper1
htmlHelper, Expression
1 expression,
IEnumerable`1 selectList) +85
ASP.views_reservation_new_aspx.__RenderMainContent(HtmlTextWriter
__w, Control parameterContainer) in c:\code\GTCC Culinary
Reservation\src\CulinaryReservation.WebMVC\Views\Reservation\New.aspx:11
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter
writer, ICollection children) +109
System.Web.UI.Control.RenderChildren(HtmlTextWriter
writer) +8
System.Web.UI.Control.Render(HtmlTextWriter
writer) +10
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter
writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter
writer, ControlAdapter adapter) +100
System.Web.UI.Control.RenderControl(HtmlTextWriter
writer) +25
ASP.views_shared_site_master.__Render__control1(HtmlTextWriter
__w, Control parameterContainer) in c:\code\GTCC Culinary
Reservation\src\CulinaryReservation.WebMVC\Views\Shared\Site.Master:66
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter
writer, ICollection children) +109
System.Web.UI.Control.RenderChildren(HtmlTextWriter
writer) +8
System.Web.UI.Control.Render(HtmlTextWriter
writer) +10
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter
writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter
writer, ControlAdapter adapter) +100
System.Web.UI.Control.RenderControl(HtmlTextWriter
writer) +25
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter
writer, ICollection children) +208
System.Web.UI.Control.RenderChildren(HtmlTextWriter
writer) +8
System.Web.UI.Page.Render(HtmlTextWriter
writer) +29
System.Web.Mvc.ViewPage.Render(HtmlTextWriter
writer) +56
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter
writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter
writer, ControlAdapter adapter) +100
System.Web.UI.Control.RenderControl(HtmlTextWriter
writer) +25
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean
includeStagesAfterAsyncPoint) +3060

This post describes the same problem. And like that post, if I change my NewReservation.SelectedServiceDate from DateTime to string, things seem to work. But everything I have read indicates this is a bug that should have been fixed in an MVC2 release candidate.

Am I doing something wrong? I don’t want the property’s type to be string, it needs to be DateTime. Shouldn’t I be able to use objects that reflect my problem?

  • 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-05-16T11:22:57+00:00Added an answer on May 16, 2026 at 11:22 am

    A multiple select list could be empty (for example if the user makes no selection) meaning that you cannot bind to a value type (like DateTime). You could use a nullable DateTime instead:

    public class NewReservation
    {
        public SelectList AvailableServiceDates { get; set; }
        public DateTime? SelectedServiceDate { get; set; }
    }
    

    Also notice that in a multiple select list the user could perform multiple selections meaning that binding to a single date doesn’t look very natural. IMHO it would be more natural to have this:

    public class NewReservation
    {
        public SelectList AvailableServiceDates { get; set; }
        public IEnumerable<DateTime> SelectedServiceDates { get; set; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.