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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:26:03+00:00 2026-05-25T00:26:03+00:00

I need to create a select list, preserving the state, which is not part

  • 0

I need to create a select list, preserving the state, which is not part of the model passed to the view. I suppose I should be using a ViewBag to pass a List to the View ? Any advise on implementation and how to preserve the state of the select list (how do I pass the selected value back to action and to the view again (possible ways of doing this) ?

The Action as of now:

public ActionResult Images(string x, string y)
{
//some code 

ContentPage cp = this.ContentPage;

return View(cp);
} 

//Post to action with same name:
[HttpPost]
public ActionResult Images(string someParameter)
 {

    ContentPage cp = this.ContentPage;

    return View(cp);
 }

The view as of now :

@model ContentPage
@{
ViewBag.Title = "Images";
CmsBaseController controller = (this.ViewContext.Controller as CmsBaseController);
}
@using (Html.BeginForm())
{ 
<div>

//This should go to List<SelectListItem> as I understand
<select name="perpage" id="perpage" onchange='submit();'>
           <option value="1">1</option>
           <option value="2">2</option>
           <option value="3">3</option>

</select>
</div>
}

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-25T00:26:04+00:00Added an answer on May 25, 2026 at 12:26 am

    Have you taken a look at this SO question? The answer there looks like it would do the trick if you wanted to use ViewBag/ViewData to pass in that list.

    That said, why not just create a quick viewmodel and store it there? It really is a simple way to go.

    I don’t know what your ContentPage model is but you could certainly make a ContentPageViewModel that has whatever stuff (including the values for the select list) that is necessary for the page.


    Example:

    It would easy enough, for example, to have a property on the viewmodel to hold the selection and a property that holds some enumeration of possible values. Something like this:

    public class MyViewModel
    {
       ...
    
       public int SelectedId { get; set; }
    
       ...
    
       public IEnumerable<Choice> Choices { get; set; }
    }
    

    where Choice, in my example, is a class that has two properties, one that holds some identifier and the other the text to display. Something like this:

    public class Choice
    {
       public int Id { get; set; }
       public string Text { get; set; }
    }
    

    And then you could just have, perhaps, a DropDownListFor which handles the display/selection work for you. Something like this:

    @model MyViewModel
    
    @Html.DropDownListFor(model => model.SelectedId, new SelectList(Model.Choices, "Id", "Text"), "Choose... ")
    

    Back in your controller’s action, the viewmodel’s SelectedId will get populated with the corresponding Id for the Choice picked view the dropdown.

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

Sidebar

Related Questions

I'm using the Zend_Form_Element_Select to create my select list, but when I view the
Need to create a custom DNS name server using C which will check against
I need to create an ASP page (classic, not ASP.NET) which runs remote shell
I need to create a php array from a very large HTML select list.
I need to create a view where I'll list certain attributes. To be more
i need create an email list sending to many emails. what is best solution
I need to create a drop down menu in struts2 from List. How can
I needed to create a custom select list for the user registration page that
Is there a way to output select list to a string in the View
I need to create radio buttons in listview. I need to select any one

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.