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 9117785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:58:42+00:00 2026-06-17T04:58:42+00:00

When I am changing the model => model.id to model => model.Supplierid i am

  • 0

When I am changing the "model => model.id" to "model => model.Supplierid" i am getting below error

“The parameter ‘expression’ must evaluate to an IEnumerable when
multiple selection is allowed.”

please have look on below code

// this my model class

public class clslistbox{
public int id { get; set; }
public int Supplierid { get; set; }
public List<SuppDocuments> lstDocImgs { get; set; }

public class SuppDocuments
{
    public string Title { get; set; }
    public int documentid { get; set; }
}
public List<SuppDocuments> listDocImages()
{
    List<SuppDocuments> _lst = new List<SuppDocuments>();
    SuppDocuments _supp = new SuppDocuments();
    _supp.Title = "title";
    _supp.documentid = 1;
    _lst.Add(_supp);
    return _lst;
} 
}

// this my controller

    [HttpGet]
    public ActionResult AddEditSupplier(int id)
    {

        clslistbox _lst = new clslistbox();
        _lst.lstDocImgs= _lst.listDocImages();
        return View(_lst);
    }

// this is view where i am binding listboxfor

@model clslistbox
@using (Html.BeginForm("AddEditSupplier", "Admin", FormMethod.Post))
{
    @Html.ListBoxFor(model => model.id, new SelectList(Model.lstDocImgs, "documentid", "title"))
}

Can anyone see the reason for it?

  • 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-17T04:58:43+00:00Added an answer on June 17, 2026 at 4:58 am

    I think the changing of the property in the expression here is a red-herring – it won’t work in either case.

    Update

    However, see at the end of my answer for some probably needlessly detailed exposition on why you didn’t get an error first-time round.

    End Update

    You’re using ListBoxFor – which is used to provide users with multiple selection capabilities – but you’re trying to bind that to an int property – which cannot support multiple selection. (It needs to be an IEnumerable<T> at least to be able to bind a list box to it by default in MVC)

    I think you mean to be using DropDownListFor – i.e. to display a list of items from which only one can be selected?

    If you’re actually looking for single-selection semantics in a listbox, that’s trickier to do in MVC because it’s Html helpers are geared entirely around listboxes being for multiple selection. Someone else on SO has asked a question about how to get a dropdown to look like a list box: How do I create a ListBox in ASP.NET MVC with single selection mode?.

    Or you could generate the HTML for such a listbox yourself.

    (Update) – Potentially needlessly detailed exposition(!)

    The reason you don’t get an exception first time round is probably because there was no value for id in ModelState when the HTML was generated. Here’s the reflected MVC source (from SelectExtensions.SelectInternal) that’s of interest (the GetSelectListWithDefaultValue call at the end is the source of your exception):

    object obj = 
      allowMultiple ? htmlHelper.GetModelStateValue(fullHtmlFieldName, typeof(string[])) : 
        htmlHelper.GetModelStateValue(fullHtmlFieldName, typeof(string));
    if (!flag && obj == null && !string.IsNullOrEmpty(name))
    {
      obj = htmlHelper.ViewData.Eval(name);
    }
    if (obj != null)
    {
      selectList = 
        SelectExtensions.GetSelectListWithDefaultValue(selectList, obj, allowMultiple);
    }
    

    Note first that the control variable allowMultiple is true in your case, because you’ve called ListBoxFor. selectList is the SelectList you create and pass as the second parameter. One of the things that MVC (unfortunately in some cases) does is to use ModelState to modify the select list you pass when re-displaying a view in order to ensure that values which were set in ModelState via a POST are re-selected when the view is reloaded (this is useful when page validation fails because you won’t copy the values to your underlying model from ModelState, but the page should still show those values as being selected).

    So as you can see on the first line, the model’s current value for the expression/field you pass is fished out of model state; either as a string array or as a string. If that fails (returns null)then it makes another go to execute the expression (or similar) to grab the model value. If it gets a non-null value from there, it calls SelectExtensions.GetSelectListWithDefaultValue.

    As I say – what you’re trying to do will ultimately not work in either the case of Id or SupplierId (because they would need to be IEnumerable) but I believe this ModelState->Eval process is yielding a null value when you use Id, so the process of getting an ‘adjusted’ SelectList is skipped – so the exception doesn’t get raised. The same is not true when you use SupplierId because I’ll wager that there’s either a value in ModelState at that point, or the ViewData.Eval successfully gets an integer value.

    Not throwing an exception is not the same as working!.

    End update

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

Sidebar

Related Questions

When changing the selected item in a ListBox, I'm getting a weird error where
FIXED BY: changing model names to match rails naming conventions I'm getting the following
EDIT I've tried changing the table model back to DefaultTableModel but I am getting
After changing the import as a from-import i'm running into this error: from datetime
Lots out there about changing model names only or mapping new models to existing
My understanding of changing db.Model schemas is that it 'doesn't matter' if you add
A client of mine has a dynamic changing business model, they sell products according
I want to simulate data changing in the model and having that data be
I want to calculate the age in view class without changing the model class
Grails does automatic schema modifications (including index/foreign key updates) when changing the domain model.

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.