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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:23:58+00:00 2026-05-22T17:23:58+00:00

I am building my own HtmlHelper extensions for standard DropDownLists that appear on many

  • 0

I am building my own HtmlHelper extensions for standard DropDownLists that appear on many of my views. On other elements I use “EditorFor” and razor generates the proper element “name” attribute for me since that is important for it to be bound to the model correctly. How would I get the correct name in my View so that my Helpers name the element appropriately?

Currently my view code looks like this, but I’d rather not hardcode the element name if I can avoid it.

<tr>
    <td class="editor-label">
        County:
    </td>
    <td class="editor-field">
        @Html.CountyDropDown("CountyID")
    </td>
</tr>

Here is my extension code (Which returns the list of Counties based on the current user’s region):

<Extension()> _
Public Function CountyDropDown(ByVal html As HtmlHelper, ByVal name As String) As MvcHtmlString
    Dim db As New charityContainer
    Dim usvm As New UserSettingsViewModel


    Dim ddl As IEnumerable(Of SelectListItem)
    ddl = (From c In db.Counties Where c.RegionId = usvm.CurrentUserRegionID
                            Select New SelectListItem() With {.Text = c.Name, .Value = c.Id})

    Return html.DropDownList(name, ddl)
End Function
  • 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-22T17:23:59+00:00Added an answer on May 22, 2026 at 5:23 pm

    I’m a dummy I already knew how to do this:

    1) Gave my Id value a UIHint in the ViewModel like so:

    <UIHint("County")>
    Public Property CountyId As Nullable(Of Integer)
    

    2) Changed my View to just use EditorFor like this:

        <td class="editor-field">                
            @Html.EditorFor(Function(x) x.CountyId)
        </td>
    

    3) Made a “County.vbhtml” partial-view in my EditorTemplates folder:

    @ModelType Nullable(Of Integer)
    @Html.DropDownList("", Html.CountySelectList(Model))
    

    4) Returned just an IEnumerable(Of SelectListItem) from my helper, not the entire drop down html:

        Public Function CountySelectList(Optional ByVal selectedId As Nullable(Of Integer) = 0) As IEnumerable(Of SelectListItem)
            Dim db As New charityContainer
            Dim usvm As New UserSettingsViewModel
            Dim CurrentUserRegionID = usvm.CurrentUserRegionID
    
            Dim ddl As IEnumerable(Of SelectListItem)
            ddl = (From c In db.Counties Where c.RegionId = CurrentUserRegionID
                                    Select New SelectListItem() With {.Text = c.Name, .Value = c.Id, .Selected = If(c.Id = selectedId, True, False)})
    
            Return ddl
        End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building my own local search UI element that gives local search suggestions
I'm currently building my own login script and have noticed that most append the
I was building my own class that resides in /lib folder and debugging with
I recently tried building my own shared and weak pointers. Code that compiles using
I'm building my own JSP Tag Library which need to support some features that
Im building an own php framework. I saw in other frameworks there are even
I have for some time now being building my own calendar because the standard
Im building my own forum where you can use diffrent types of BBcode and
I'm currently building my own set of Form elements with Zend_Form and want all
I am building my own CRM access database that will contain a list of

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.