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

  • Home
  • SEARCH
  • 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 6739119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:26:58+00:00 2026-05-26T11:26:58+00:00

I am developing an ASP.Net MVC 3 web application. The app currently is connected

  • 0

I am developing an ASP.Net MVC 3 web application. The app currently is connected to a database that has several tables, two of which are Category(catId, Name) and Site(siteID, Name).

I wish to create a view that has two drop down lists, one for each of the tables mentioned, so that the user can select from and then run a report. To do this I have created a viewModel to represent the two drop down lists

public class ReportSiteCategorySearchViewModel
{
    public SelectList categoryList { get; set; }
    public SelectList siteList { get; set; }
}

Then in my controller that returns the viewModel I have the following

public ActionResult getEquipmentByCategoryAndSite()
    {
        ReportSiteCategorySearchViewModel viewModel = new ReportSiteCategorySearchViewModel
        {
            categoryList = new SelectList(categoryService.GetAllCategories().ToList(), "categoryID", "categoryTitle"),
            siteList = new SelectList(siteService.GetAllSites().ToList(), "siteID", "title")
        };

        return View(viewModel);
    }

I then pass to a view which takes this viewModel and writes out the values to the drop downs

<div>
    <label for="ddlSite">Sites</label>
    @Html.DropDownList("ddlSite", Model.siteList, "All Sites")
    &nbsp;&nbsp;
    <label for="ddlCatgeory">Categories</label>
    @Html.DropDownList("ddlCatgeory", Model.categoryList, "All Categories")
</div>

This works, however, I am not sure this is the best way to do it. I am just wondering is my method correct, is there a better way to do this? Ie, what if I needed 5/6 more drop down lists from other tables, should I just add to the current viewModel etc?

Any feedback would be much appreciated.

Thank You.

  • 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-26T11:26:59+00:00Added an answer on May 26, 2026 at 11:26 am

    You can create a viewModel of type List<SelectList> In your controller, add each table (as a SelectList as you’re doing) to this model. Then pass the view the model, which is a list of SelectLists.

    Then you can iterate through each value in your view:

    <div>
    @foreach(SelectList SL in Model)
    {
       <label for="ddl"+SL>SL.Title</label>
       @Html.DropDownList("ddl"+SL.Title, sl.list, sl.items")
    }
    

    You may need to modify your list of SelectList to include the ‘Title’ or ‘items’ field. By doing it this way you can keep adding elements to the List, and you won’t need to update the view.

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

Sidebar

Related Questions

We are developing an ASP.NET MVC Application that currently uses it's own database ApplicationData
Im developing a web application in asp.net mvc (c#) that has a form and
I am developing an asp.net mvc web application that makes much use of jquery
We are currently developing a web application in ASP.NET MVC which would really benefit
I have an Asp.Net MVC Web Application that I am developing. I have TeamCity
I'm developing a web app in asp.net mvc using jquery, the language of application
I'm developing a web application based on ASP.NET MVC. There are a large database.
Hello i am currently developing a ASP.NET MVC 3 application that uses the new
I'm developing a web application using ASP .NET MVC 1.0 and jQuery (including the
I am developing asp.net mvc web app with MongoDB as the data storage. I

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.