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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:08:02+00:00 2026-05-27T21:08:02+00:00

I have an HTML dropdown list: <select name=status> <option value=close >Close Task</option> <option value=open

  • 0

I have an HTML dropdown list:

<select name="status">  
       <option value="close" >Close Task</option>
       <option value="open" >Reopen Task</option>
  </select>

I want to set the ‘selected’ option based on the ‘Task.Completion’ property in my view model:

public class TaskEditViewModel
{
    public Task Task { get; set; }
    public TaskComment TaskComment { get; set; }
}

So if Task.Completion is NULL, the ‘close’ option is selected, otherwise the ‘open’ option is selected.

How can I do this?

  • 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-27T21:08:03+00:00Added an answer on May 27, 2026 at 9:08 pm

    Your view model doesn’t seem adapted to what you are trying to do in the view (which according to your question is show a dropdown list and preselect a value based on some property on your view model).

    So a far more realistic view model would be this:

    public class TaskEditViewModel
    {
        public string Completion { get; set; }
        public IEnumerable<SelectListItem> Actions 
        { 
            get
            {
                return new[]
                {
                    new SelectListItem { Value = "close", Text = "Close Task" },
                    new SelectListItem { Value = "open", Text = "Reopen Task" },
                };
            }
        }
    }
    

    then you could have a controller action which will populate and pass this view model to the view:

    public ActionResult Foo()
    {
        var model = new TaskEditViewModel();
    
        // this will automatically preselect the second item in the list
        model.Completion = "open";
    
        return View(model);
    }
    

    and finally inside your strongly typed view you could use the DropDownListFor helper to render this dropdown:

    @model TaskEditViewModel
    @Html.DropDownListFor(x => x.Completion, Model.Actions)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

if i have a dropdown with the following html: <select id=myDropdown name=myDropdown> <option value=6>Six</option>
I have this HTML dropdown: <form> <input type=text id=realtxt onkeyup=searchSel()> <select id=select name=basic-combo size=1>
I have a drop down list like so: <%= Html.DropDownList(SoldTo, Model.SellDealerList, Select a Dealer)%>
i have an asp.net mvc page and i want to have a dropdown list
I have a dropdown list on my asp.net mvc site: <%= Html.DropDownList(CustCodes) %> My
I want to use php array for HTML select list. In this case it
If I have a drop down list as follows <div class=editor-label> <%= Html.DropDownListFor(model =>
Consider the following HTML snippet. The desired effect is to have a dropdown be
I have a drop down in html. When I change the value of the
Basically, I have populated a dropdown list using php from a database on a

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.