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

The Archive Base Latest Questions

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

How do I get the drop down to display as part of my editor

  • 0

How do I get the drop down to display as part of my editor template?

So I have a Users entity and a Roles entity. The Roles are passed to the view as a SelectList and User as, well, a User. The SelectList becomes a drop down with the correct ID selected and everything thanks to this sample.

I’m trying to get an all-in-one nicely bundled EditorTemplate for my entities using MVC 3 so that I can just call EditorForModel and get the fields laid out nicely with a drop down added whenever I have a foreign key for things like Roles, in this particular instance.

My EditorTemlates\User.cshtml (dynamically generating the layout based on ViewData):

<table style="width: 100%;">
@{
    int i = 0;  
    int numOfColumns = 3;

    foreach (var prop in ViewData.ModelMetadata.Properties
        .Where(pm => pm.ShowForDisplay && !ViewData.TemplateInfo.Visited(pm))) 
    { 
        if (prop.HideSurroundingHtml) 
        { 
            @Html.Display(prop.PropertyName) 
        }
        else 
        { 
            if (i % numOfColumns == 0)
            {

                @Html.Raw("<tr>");
            }

            <td class="editor-label">
                @Html.Label(prop.PropertyName)
            </td>
            <td class="editor-field">
                @Html.Editor(prop.PropertyName)
                <span class="error">@Html.ValidationMessage(prop.PropertyName,"*")</span>
            </td>

            if (i % numOfColumns == numOfColumns - 1)
            {
                @Html.Raw("</tr>");
            }
            i++;
        }
    }
}
</table>

On the View I’m then binding the SelectList seperately, and I want to do it as part of the template.

My Model:

public class SecurityEditModel
{
    [ScaffoldColumn(false)]
    public SelectList roleList { get; set; }

    public User currentUser { get; set; }
}

My Controller:

public ViewResult Edit(int id)
{
    User user = repository.Users.FirstOrDefault(c => c.ID == id);

    var viewModel = new SecurityEditModel
        {
            currentUser = user,
            roleList = new SelectList(repository.Roles.Where(r => r.Enabled == true).ToList(), "ID", "RoleName")
        };

    return View(viewModel);
}

My View:

@model Nina.WebUI.Models.SecurityEditModel

@{
    ViewBag.Title = "Edit";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Edit</h2>


@using(Html.BeginForm("Edit", "Security"))
{
    @Html.EditorFor(m => m.currentUser)
    <table style="width: 100%;">
        <tr>
            <td class="editor-label">
                User Role:
            </td>
            <td class="editor-field">
                <!-- I want to move this to the EditorTemplate -->
                @Html.DropDownListFor(model => model.currentUser.RoleID, Model.roleList)
            </td>
        </tr>
    </table>
    <div class="editor-row">
        <div class="editor-label">

        </div>
        <div class="editor-field">

        </div>
    </div>
    <div class="editor-row">&nbsp;</div>
    <div style="text-align: center;">
        <input type="submit" value="Save"/>&nbsp;&nbsp;
        <input type="button" value="Cancel" onclick="location.href='@Url.Action("List", "Clients")'"/>
    </div>

}       

Hopefully that’s clear enough, let me know if you could use more clarification. Thanks in advance!

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

    Since you need access to the SelectList you can either create an editor template bound to SecurityEditModel or you can pass the SelectList in ViewData. Personally I would go with the strongly typed approach.

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

Sidebar

Related Questions

View Here: http://174.132.101.73/~ree/header/ I have a drop down box. I am trying to get
I have two drop down menus where the options are not get from the
I have about 10 drop down list controls that get populated. Instead of copying/pasting
I have 10 items in drop down and want to display only first 5
I am trying to get a drop-down list to display column data containing countries
I'm trying to get a drop down list to display multiple columns from a
Im using Ajax to get a value from the Drop down box and display
How do I get UITableView to display as drop-down list? I want to enable
I am having a hard time figuring out how to get cascading drop down
Hi I am wondering how to create dynamic drop down lists that get refined

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.