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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:11:20+00:00 2026-05-31T05:11:20+00:00

Alright, so here’s the deal. I would like to be able to create a

  • 0

Alright, so here’s the deal. I would like to be able to create a custom dropdown box from an System.Linq.Expressions.Expression in c#. I know there are helpers, like DropDownListFor, but I’m not sure how to make one from scratch, or how to pull the values etc from the expression.

Essentially why I’m doing this is if you use DropDownListFor it will ‘select’ an <option> based on it’s value, but I want to ‘select’ an option based on it’s text instead. So if anyone has an idea how to do that instead, that would be great.

This is essentially what I have so far

public static MvcHtmlString ValidatedEditableDropDownListFor<TModel,TProperty>(
        this HtmlHelper<TModel> htmlHelper,
        Expression<Func<TModel, TProperty>> expression,
        SelectList list,
        String defaultOption,
        Object attribs)
{
    //Basically puts the strings into a html template<div>{0}{1}</div> etc.
    return GetValidatedHtml(
        htmlHelper.LabelFor(expression).ToString() ,
        htmlHelper.DropDownListFor(expression , list , defaultOption , attribs).ToString()
        ,htmlHelper.GetValidatedErrorMessage(expression),false,"EditableDropDown");
}

Any ideas on how I can have the DropDownListFor make an <option> selected, or how to create my own html element based on the Expression and SelectList would be greatly appreciated.

Thanks.

  • 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-31T05:11:21+00:00Added an answer on May 31, 2026 at 5:11 am

    Why not pass your list of SelectedListItems to your view with the correct one selected by it’s text from your controller

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

Sidebar

Related Questions

Alright I got something really tricky here... I would like to DRAW/USE Headers to
Alright so here are my two tables. CREATE TABLE [cards] ( [id] TEXT PRIMARY
Alright...I am here looking for some bread crumbs. This is my code: using System;
Alright, here I am again trying to write code from scratch and I can't
Alright, here is the output I get: arm-none-linux-gnueabi-ld --entry=main -dynamic-linker=/system/bin/linker -rpath-link=/home/oem/android-ndk-r3/build/platforms/android-5/arch-arm/usr/lib -L/home/oem/android-ndk-r3/build/platforms/android-5/arch-arm/usr/lib -nostdlib -lstdc++
Alright, here's an odd one from an MS Access database I'm running. I have
Alright, so what I'm attempting to do here, is select from a datatable all
Alright so here's my current code: import System.IO import System.Environment import System.Directory main =
Alright, here's the deal: I have a nice little 4Gb table called Mails on
Alright here's the deal, I'm taking an intro to C++ class at my university

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.