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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:15:10+00:00 2026-06-12T11:15:10+00:00

Thanks to help I got here – I have the following code in my

  • 0

Thanks to help I got here – I have the following code in my controller:

 var stands = db.Stands.ToList().Where(s => s.ExhibitorID == null)
              .Select(s => new SelectListItem
              {
                  Value = s.StandID.ToString(),
                  Text = s.Description + "-- £" + s.Rate.ToString()
              });


        ViewBag.StandID = new SelectList(stands, "Value", "Text");

And render it in my view like this:

<div class="editor-field"> 
    @Html.DropDownList("StandID", new {style = "width:150px"})
</div> 

However in the view, I get the following error:

CS1928: ‘System.Web.Mvc.HtmlHelper’ does not contain a definition for ‘DropDownList’ and the best extension method overload ‘System.Web.Mvc.Html.SelectExtensions.DropDownList(System.Web.Mvc.HtmlHelper, string, string)’ has some invalid arguments

It’s fine when I remove the new {style=….

How can I set the width of the dropdownlist, without getting this error?

Thank you,

Mark

  • 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-12T11:15:11+00:00Added an answer on June 12, 2026 at 11:15 am

    You need to make a few changes. First, change your controller code from this:

    ViewBag.StandID = new SelectList(stands, "Value", "Text");
    

    To this:

    ViewBag.StandList = new SelectList(stands, "Value", "Text");
    

    Second, change your helper to this:

    @Html.DropDownList("StandID", (SelectList)ViewBag.StandList, new {style = "width:150px"})
    

    It’s important to make sure the html elements name is different from the collection of items, otherwise all kinds of problems occur.

    It’s even better to use a strongly typed view model.

    @Html.DropDownListFor(m => m.StandID, Model.StandList, new {style="width:150px;"})
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Thanks to the help in a previous question , I've got the following code
I have a show/hide toggle working well in multiple instances (thanks to help here
I've already got help here for creating a quotation extraction function. Thanks alot, soulmerge!
Thanks to some help I received yesterday I've got some dynamic summing working on
Thanks to the brilliant help on my XML parsing problem I got to a
Thanks for the help on here with my query on here the other day
Thanks for your help! I'd like to output all companyName entries that have uploads
Thanks to pbos help and its program (published here , for xoring a big
Thanks to the help here and on the RestKit mailing list I've been able
Here what I have got: Qt SDK version 4.6.2 Windows XP Question: how can

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.