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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:48:42+00:00 2026-06-07T22:48:42+00:00

Ok dokey, I have the following set up. Model public class SupplyType { [Key]

  • 0

Ok dokey, I have the following set up.

Model

public class SupplyType
{
    [Key]
    public int SupplyTypeId { get; set; }
    public string SupplyTypeName { get; set; }

}

public class Supply
{
    [Display(Name = "What type of supply is this from?")]
    public int SupplyTypeId { get; set; }
    public IEnumerable<SupplyType> SupplyType { get; set; }
}

Controller

  public ActionResult (Guid id)
    {
            var model = Model(id);
            model.Supply.SupplyType = db.SupplyTypes.ToList();
            return View(model.);    
    }

I now have a View of the following

 //Good view
      <div class="editor-label">
                @Html.LabelFor(model => model.SupplyTypeId, "SupplyType")
            </div>
            <div class="editor-field">
       @Html.DropDownListFor(x => x.SupplyTypeId, new SelectList(Model.SupplyType, "SupplyTypeId", "SupplyTypeName"))
          @Html.ValidationMessageFor(model => model.SupplyTypeId)
        </div>

This works fine and dandy, if I don’t pass touch it, then validation does not fire and I can click on post buttons on my page.

However, when I try and implement a ” — Please Select — ” item in the list, the validation strikes and I’m stuck, can’t click on one of my post buttons..boo!!

 //Bad view
  <div class="editor-label">
            @Html.LabelFor(model => model.SupplyTypeId, "SupplyType")
        </div>
        <div class="editor-field">
   @Html.DropDownListFor(x => x.SupplyTypeId, new SelectList(Model.SupplyType, "SupplyTypeId", "SupplyTypeName"), " -- Please Select -- ")
      @Html.ValidationMessageFor(model => model.SupplyTypeId)
    </div>

I still require a ” — Please Select — ” item in the drop down but I don’t want the validation to strike if this hasn’t been set.

Any ideas of how I can get around this without turning validation off completely? The reason for this is that the drop down lists will be conditionally shown and therefore might not need to be populated.

Any help greatly received.

  • 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-07T22:48:45+00:00Added an answer on June 7, 2026 at 10:48 pm

    For your specific requirement like this, I think the simple way is to add -- Please Select -- as a new List Item with SupplyTypID value as 0.

    public ActionResult (Guid id)
    {
            var model = Model(id);
            model.Supply.SupplyType = db.SupplyTypes.ToList();
            model.Supply.SupplyType.Add(new 
                       {
                         SupplyTypID=0, SupplyTypeName=" Please Select"
                       });
    
            return View(model);    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class like the following: public class DropDownControl<T, Key, Value> : BaseControl
I have an element that can have an arbitrary background colour (set via a
Okay I have a JSON file and it has a set of objects that
I have created a SecretkeySpec object wich contains a 128 bit key. I would
I have a web service class that the rest of the framework depends on
Is there anyway to get $self into a MooseX::Types coercion? I have other data
Okey dokey, I have a jQuery function that checks the height of 2 divs
Consider: List<String> someList = new ArrayList<>(); // add "monkey", "donkey", "skeleton key" to someList
I have a colour scheme based around yellow, for warning messages on a website.
Imagine I have this object (written with Ruby literals) stored in a MongoDB: {tags

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.