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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:44:12+00:00 2026-05-17T22:44:12+00:00

let me ask the question first. Where is the correct place to call a

  • 0

let me ask the question first.

Where is the correct place to call a function that load a list of values to be display on a view?

I create a controller like this

public ActionResult Create()
{
    SeaModel newSea = new SeaModel();

    return View("Season/CreateSea", newSea);
}

//I not quite sure if this should go here or in another place
partial class seaDataContext
{
    public List<string> getSeaSettings()
    {
        var seaSettings = from p in settings
                          where p.setting == "periods"
                          select p.value;

        return seaSettings.ToList<string>();                              
    }
}

The model is like

public class SeaModel
{
    [Required(ErrorMessage="*")]
    [Display(Name = "Period Name")]
    public string periods { get; set; }    
}

Which create a view like

  @using (Html.BeginForm()) {
        @Html.ValidationSummary(true, "Please correct the following errors.")

        <fieldset>
            <legend>Fields</legend>

            <div class="editor-label">
                @Html.LabelFor(model => model.periods)
            </div>
            <div class="editor-field">
                @Html.Select(model => model.periods, ****My doubt comes here****)
                @Html.ValidationMessageFor(model => model.periods)
            </div>

            <p>
                <input type="submit" value="Create" />
            </p>
        </fieldset>

    }

so, How and where do I pass the return of getSeaSettings() to the view?

Thanks

  • 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-17T22:44:13+00:00Added an answer on May 17, 2026 at 10:44 pm

    best practice is to make a Selectlist in your Model for this dropdown.

    however you also can use the more easy option: using ViewData

     public ActionResult Create()
     {
         SeaModel newSea = new SeaModel();
    
         ViewData["myDropDown"] = new SelectList(listOfObjects, "valueOfTheObjectLikeID", "NameYouWantToShowInDropdown");
    
         return View("Season/CreateSea", newSea);
     }
    

    then:

    @Html.Select(model => model.periods, ViewData["myDropDown"] as SelectList)
    

    dont forget in your [HttpPost] method to also fill in the viewdata if you’r validation fails, so the dropdown can be rebuilt.

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

Sidebar

Related Questions

before I ask my question I wanted to let everybody know that I appreciate
First, let me ask you to consider this as a real question, and not
I asked a related question about findbugs, but let's ask a more general question.
Let's say we have a simple function defined in a pseudo language. List<Numbers> SortNumbers(List<Numbers>
I'm writing a program for iPhone that will first let the user take a
my first question on Stackoverflow. Let me start with a bit of code. It's
I wanted to ask a question... Let's say there are 2 people: Peter and
Let's say you create a wizard in an HTML form. One button goes back,
Let me try to explain what I need. I have a server that is
Let's say I'm writing a PHP (>= 5.0) class that's meant to be a

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.