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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:08:19+00:00 2026-06-06T09:08:19+00:00

this is my drop down list: @Html.DropDownListFor(m => m.ReportType, new SelectList(ViewBag.DateRange as List<SelectListItem>, Value,

  • 0

this is my drop down list:

@Html.DropDownListFor(m => m.ReportType, new SelectList(ViewBag.DateRange as List<SelectListItem>, "Value", "Text"), new { @class = "w150" })

I cannot figure out where to put the default value in there? My default value would be ‘ThisMonthToDate’

Any suggestions?

  • 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-06T09:08:21+00:00Added an answer on June 6, 2026 at 9:08 am

    If you have a Model bounded to your view, I strongly recommend you to avoid using ViewBag and instead add a Property to your Model/ViewModel to hold the Select List Items. So your Model/ViewModel will looks like this

    public class Report
    {
       //Other Existing properties also
       public IEnumerable<SelectListItem> ReportTypes{ get; set; }
       public string SelectedReportType { get; set; }
    }
    

    Then in your GET Action method, you can set the value , if you want to set one select option as the default selected one like this

    public ActionResult EditReport()
    {
      var report=new Report();
      //The below code is hardcoded for demo. you mat replace with DB data.
      report.ReportTypes= new[]
      {
        new SelectListItem { Value = "1", Text = "Type1" },
        new SelectListItem { Value = "2", Text = "Type2" },
        new SelectListItem { Value = "3", Text = "Type3" }
      };      
      //Now let's set the default one's value
      objProduct.SelectedReportType= "2";  
    
      return View(report);    
    }
    

    and in your Strongly typed view ,

    @Html.DropDownListFor(x => x.SelectedReportType, 
         new SelectList(Model.ReportTypes, "Value", "Text"), "Select Type..")
    

    The HTML Markup generated by above code will have the HTML select with the option with value 2 as selected one.

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

Sidebar

Related Questions

I have this drop-down list of countries: <select name=country> <option value=>Country...</option> <option value=Afganistan>Afghanistan</option> <option
I'm rendering a drop down list using Html.DropDownListFor() extension. The markup I get is
please look at this example of drop down checkbox list im working on.. http://jsfiddle.net/Yojik/VJHVK/143/
I wrote this little function to fill a drop down list with data from
I'm using this codes for listing custom field values into drop-down list element on
I have this to populate a drop down list in an ASP.NET MVC view.
So I have a drop-down list and a text-box: <table> <tr> <td>Group Name: </td>
I have this my view @Html.DropDownListFor(model => model.StateCode, Model.StateList, Select, new { @style =
I'm trying to replicate an HTML SELECT element (drop-down-list or combobox) in Flash (AS3).
I have a view that is displaying a Drop down list using the HTML

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.