MVC: Populate a <select> from SQL Server database

I have the below example html select (dropdown)

<select name="Testing">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
<option value="4" selected>Select</option>
</select>

And the following SQL Server Table:

  • Linq-To-Entities subquery with string concatenation
  • Deleting/Ignoring Duplicate Records In A Table And Keeping Only the Earliest Ones
  • replace only matches the beginning of the string
  • In SQL Server is there any difference between not(columnName='value') and columnName<>'value'?
  • Execution Time Slower with each Iteration of the same SPROC
  • SP_Who does not return DBName Column
  • ID NAME
    1  Apple
    2  Orange
    3  Peach
    

    This drop down is part of a form which is posted to server, the value is read using:

    reqparm.Add("TestDropdown", Request["Testing"].ToString());
    

    How do I populate the drop down while keeping the name attribute?

    One Solution collect form web for “MVC: Populate a <select> from SQL Server database”

    In the end the solution I produced avoided the html helpers (personally don’t like them)

    In your index method of home controller:

    // create list of my viewmodel policyorg equals my db table in a list
    
    List<PolicyOrganisation> policyOrgs = db.PolicyOrganisations.ToList();
    
    // pass results to viewbag
    
    ViewBag.PolicyOrgs = policyOrgs;
    

    then in Index.cshtml

    // Loop throught items in viewbag and add each to the select
    
    <select id="DD1" name="PolicyOrganisation">
                            <option value="-1">Select</option>    
                            @foreach (var item in ViewBag.PolicyOrgs)
                            {
                                <option value="@item.Id">@item.Name</option>
                            }
                        </select>
    
    MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.