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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:22:43+00:00 2026-06-05T09:22:43+00:00

After reading this question ASP.NET MVC: Nesting ViewModels within each other, antipattern or no?

  • 0

After reading this question
ASP.NET MVC: Nesting ViewModels within each other, antipattern or no?

and Derick Bailey’s comment

i think the “consider what your viewmodel would look like as xml or
json” bit is probably the most important point, here. i often use that
perspective to help me understand what the view model should look
like, and to help me understand what data is “viewmodel” data vs “data
that goes on the HTML rendering of the view”. helps to keep things
clean and separate them nicely – Derick Bailey Apr 11 ’11 at 15:45

It makes me wonder how I would approach creating a View for a ViewModel with databound selection items. I’m really struggling because I can’t envision where the SelectList belongs. If I think in terms of JSON or XML then the SelectList is part of the View Only. All I want is a dropdown list prepopulated with a list of values for the user to select the Location Having it in the ViewModel seems wrong, but when I think about moving it to the View I don’t know where to place the logic to pull from the DB to populate the Selection List

public class SearchViewModel
{
    public int? page { get; set; }
    public int? size { get; set; }
    //Land Related search criteria        
    [IgnoreDataMember]
    public SelectList LocationSelection{ get; set; }

update

Here is a great question and answer that is really closely related
C# mvc 3 using selectlist with selected value in view

I’ve tested this implementation and it does what I think I want to do. I’m not going to rush to pick an answer as I still haven’t fully vetted this out.

  • 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-06-05T09:22:44+00:00Added an answer on June 5, 2026 at 9:22 am

    I’d refactor your viewModel along the following lines as I don’t believe that selectlists should belong in the viewmodel:

    public class SearchViewModel
    {
        public int? page { get; set; }
        public int? size { get; set; }
        //Land Related search criteria        
        public IEnumerable<Location> LocationSelection{ get; set; }
    }
    

    and in your view, populate the viewModel as such:

    public ActionResult Search()
    {
        var viewModel = new SearchViewModel()
        {
            viewModel.LocationSelection = _repository.All<Location>()
        };
    
        // any other logic here or in service class
        return View(viewModel);
    }
    

    then in your view, you’d use the html.dropdownlist helper to display your items.
    works for me

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

Sidebar

Related Questions

I am trying to learn ASP.NET MVC. After reading through many articles on the
I am posting this question after reading other similar questions about my problem but
After reading on the benefits (and using) the Repository Design pattern within an ASP.NET
After reading ASP.NET MVC 2 in Action and watching Jimmy Bogard's presentation from MvcConf
After reading this question , i saw the answer by Naveen containing a link
After reading and commenting on this question PHP Library for Keeping your site index
This seems to be an embarrassingly simple question, but, after a day of reading
After reading this question I attempted to clean out my workspace and found that
This is a question about asp.net WebForms and sessionstate. I know this is probably
I am trying to learn Asp.net Mvc so I am trying out this Tutorial.

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.