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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T10:19:02+00:00 2026-05-19T10:19:02+00:00

Im new to MVC2/3 so keep that in mind. Also, using Ajax or jQuery

  • 0

Im new to MVC2/3 so keep that in mind. Also, using Ajax or jQuery is NOT an option.

I have a web page where the user must choose an item out of a dropdown list and then hit a “Filter” button. (Clicking this button will simply trigger the default POST action in my controller and return a filtered list of results.

I have everything working except I am running into one issue. When the Filter action is complete and returns control back to my view, the dropdown list contents are lost (ie, null). The results are returned no problem, it’s just that my dropdown list is blank – thus preventing user from selecting another item out of the list.

Am I supposed to re-fill the dropdown list on the Filter action or is there a cleaner way to do this?

Here is a snapshot of my code:

My ViewModel

public class MyViewModel {
        [DisplayName("Store")]
        public IEnumerable<Store> StoreList { get; set; }

        public string SelectedStore { get; set; }
}

My View (Index.cshtml)

@using (Html.BeginForm()) {

    <h2>Search</h2>

    @Html.LabelFor(m => m.StoreList)
    @Html.DropDownListFor(m => m.SelectedStore, new SelectList(Model.StoreList, "StoreCode", "StoreCode"), "Select Store")

    <input type="submit" value="Filter" />
}

My Controller:

public class MyController : Controller
{
        public ActionResult Index() {

            MyViewModel vm = new MyViewModel();
            var storelist = new List<Store>();
            storelist.Add(new Store { StoreCode = "XX" });
            storelist.Add(new Store { StoreCode = "YY" });
            storelist.Add(new Store { StoreCode = "ZZ" });
            vm.StoreList = storelist;

            return View(vm);
        }

        [HttpPost]
        public ActionResult Index(MyViewModel model, string SelectedStore, FormCollection collection) {

            if (ModelState.IsValid) {
                /* this works, model state is valid */

                /* BUT, the contents of model.StoreList is null */
            } 

            return View( model);
        }
}
  • 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-19T10:19:02+00:00Added an answer on May 19, 2026 at 10:19 am

    Yes, you have to repopulate any models (including ViewData) that are passed to the view. Remember, it’s a stateless system, your controller is re-instantiated with every call and starts effectively from scratch.

    I would do it thus:

    public class MyController : Controller
    {
         private List<Store> GetStoreList()
         {
              List<Store> StoreList = new List<Store>();
              // ... Do work to populate store list
              return StoreList;
         }
    
         public ActionResult Index() {
    
             MyViewModel vm = new MyViewModel();
             vm.StoreList = GetStoreList();
             return View(vm);
         }
    
         [HttpPost]
         public ActionResult Index(MyViewModel model, string SelectedStore, FormCollection collection) {
    
             if (ModelState.IsValid) {
                /* this works, model state is valid */
    
                /* BUT, the contents of model.StoreList is null */
             } 
             model.StoreList = GetStoreList();
             return View( model);
         }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a mvc2 application with a view like this <% using (Ajax.BeginForm(UserApprove, new
I have created a new MVC2 project using the ASP.NET MVC2 Web Application, which
I downloaded the fairly new Ninject 2.0 and Ninject.Web.Mvc (targeting mvc2) sources today, and
I have a new solution that is an ASP.NET MVC 2.0 application. I have
Could some one please explain the advantages and disadvantages of using the new MVC2
I have a new converted MVC2 project running against the MVC2 source code. I
I am working on a very simple application, using MVC2 Preview 1. I have
I have a dropdownlist in my asp.net MVC2 view like this: <% using(Html.BeginForm(temp,Settings)){ %>
We have a web application written in ASP.NET for .NET 3.5, using standard web
I have been looking for some good MVC2 cheatsheets to help a new team

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.