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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:20:48+00:00 2026-05-23T12:20:48+00:00

I need to use jQuery to do some validation on a DropDownList. Therefore I

  • 0

I need to use jQuery to do some validation on a DropDownList. Therefore I am trying to add a htmlAttribute like this:

@Html.DropDownList("category_id", "Vælg..", new { @class = "required" })

I am getting the following errors:

Error   2   'System.Web.Mvc.HtmlHelper<MvcApplication3.Models.Question>' does not contain a definition for 'DropDownList' and the best extension method overload 'System.Web.Mvc.Html.SelectExtensions.DropDownList(System.Web.Mvc.HtmlHelper, string, System.Collections.Generic.IEnumerable<System.Web.Mvc.SelectListItem>, string)' has some invalid arguments   c:\Users\Kenan\Documents\Visual Studio 2010\Projects\MvcApplication3 - Copy\MvcApplication3\Views\AdminQuestion\GridQuestion.cshtml 38  14  MvcApplication3
Error   3   Argument 3: cannot convert from 'string' to 'System.Collections.Generic.IEnumerable<System.Web.Mvc.SelectListItem>' c:\Users\Kenan\Documents\Visual Studio 2010\Projects\MvcApplication3 - Copy\MvcApplication3\Views\AdminQuestion\GridQuestion.cshtml 38  47  MvcApplication3
Error   4   Argument 4: cannot convert from 'AnonymousType#1' to 'string'   c:\Users\Kenan\Documents\Visual Studio 2010\Projects\MvcApplication3 - Copy\MvcApplication3\Views\AdminQuestion\GridQuestion.cshtml 38  57  MvcApplication3

If I change the code to:

@Html.DropDownList("category_id", null, new { @class = "required " })

It works, but without a default value, which is not what I want.

What am I doing wrong?

  • 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-23T12:20:49+00:00Added an answer on May 23, 2026 at 12:20 pm

    You’ll notice in the Overload List that there’s no overload for string, string, object.

    The overload you may be looking for is:

    DropDownList(HtmlHelper, String, IEnumerable<SelectListItem>, Object)
    

    You’d write this in your view as:

    @Html.DropDownList("SomeString", MyEnumerable, new {@class = "required"}
    

    The reason your second example works, i.e. string, null, object is because IEnumerable<T> is nullable.

    UPDATE

    You may find that DropDownListFor is a better match for what you need.

    The exact overload you’ll probably want is:

    HtmlHelper<TModel>, Expression<Func<TModel, TProperty>>, IEnumerable<SelectListItem>, Object
    

    implimented as:

    @Html.DropDownListFor(m => m.category_id, ViewBag.category_id, new {@class = "required"})
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use a jquery validation plugin and I need to add some extra checking,
Trying to do some jQuery validation (without the plugin - please no answers like
I need some guidance on how to add a validation method to the jquery
I am trying to use jquery validation to validate some input values on the
Using ASP.NET MVC + jQuery : I need to use some values owned by
I need help to use jConfirm with this existing code (php & Jquery &
I use edit-in-place plugin: http://arashkarimzadeh.com/jquery/7-editable-jquery-plugin.html I't works Great! I just need something to check
I'm doing some simple client side validation with jQuery. var passedValidation = new Boolean(true);
I need to use Jquery to modify divs on some certain pages that ends
For some specific reasons, I need to use the jQuery 'load()' method in order

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.