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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:36:30+00:00 2026-05-27T02:36:30+00:00

I am working on a .Net MVC3 application. I have a couple different models

  • 0

I am working on a .Net MVC3 application. I have a couple different models which all have an attribute or two with a DataType of varchar(1). For each of these want to have a drop down menu for Yes/No with a value of ‘Y’ or ‘N’.

My current solution is as follows: I have a method in a public class which sends gives me my List of Yes/No values for the dropdown:

        List<SelectListItem> items = new List<SelectListItem>();
        items.Add(new SelectListItem() { Text = "Yes", Value = "Y" });
        items.Add(new SelectListItem() { Text = "No", Value = "N" });
        return items;

In my Controller, I then set this list into the ViewBag and send it into the View:

ViewBag.YesNo = new SelectList(repository.GetYesNo(), "Value", "Text");

And then I use it for a specific Model attribute like this:

@Html.DropDownListFor(model => model.PARAMETER_REQUIRED, (SelectList)ViewBag.YesNo)

This gets the job done but I don’t like the ViewBag method because it’s pretty tedious to maintain it when switching Views and I don’t like having to repeat code. I want to change this up so that I can just use

@Html.EditorFor(model => model.PARAMETER_REQUIRED)

and have Razor know that I want this to be a DropDown with my Yes/No attributes.I also want to have this be reusable so that I can use the same template for any fields (in other models) that I want to edit with this Yes/No dropdown.

Is this possible? I know that ‘templating’ DisplayFor is possible. Can we achieve something similar with EditorFor?

  • 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-27T02:36:30+00:00Added an answer on May 27, 2026 at 2:36 am

    Here are some really good examples of the built-in display templates and editor templates. Take a look at EditorTemplates/Boolean.ascx. You’ll want something like this, in fact I’m not sure why you can’t use the Boolean template as-is and change your view model to just be List or other suitable collection. Then, if necessary, you can customize the Boolean editor template to give you the exact DropDownList view you need.

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

Sidebar

Related Questions

I am working on asp.net MVC3 application and I have created a layout.cshtml which
I have working application in asp.net MVC3. Today when I was working on it
I am working on an asp.net mvc3 application with linq2sql. I have a List
I have Ninject working nicely in an ASP.NET MVC3 web application. I'd like to
I'm working on an asp.net MVC 3 application which is using Data Models from
I am working on asp.net mvc3 application and have many records coming from database.
What profilers have you used when working with .net programs, and which would you
I am working on asp.net MVC 3 application. I have created a Razor view
i am working in asp.net mvc 3 web application which uses razor code. and
I'm working on a large Asp.Net MVC3 application (>50 views) and we are currently

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.