Link to home
Start Free TrialLog in
Avatar of ITsolutionWizard
ITsolutionWizardFlag for United States of America

asked on

mvc ms sql server with List<>

Below codes working but for some reasons it supposes to return 6 records from the ms sql database.but it ends up return 1 record only.
Can you help me to fix it?

Thanks
public ActionResult Index()
        {
return View(EventFleetList());
}
public List<Domain.Fleet> EventFleetList()
        {
            Domain.Fleet f = new Domain.Fleet();
            List<Domain.Fleet> fleetList = null;
            using (SqlConnection connection = new SqlConnection(connectionString))
            using (SqlCommand command = new SqlCommand("",connection))
            {
                connection.Open();
                command.CommandText = "SELECT * FROM Fleet";
                SqlDataReader reader = command.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        string id= reader["FleetID"].ToString();
                        fleetList = new List<Domain.Fleet>()
                        {
                                new Domain.Fleet
                                {
                                    id =1,
                                    make = id + " Make",
                                    model = id + " Model"
                                },                                
                        };
                    }
                }
             }
            return fleetList;
        }             



//mvc razor
@model List<Domain.Fleet>  
@Html.AntiForgeryToken()
                @for(var i=0; i < Model.Count; i++)
                {
                  @Html.DisplayFor(x => x[i].make)                    
                  @Html.DisplayFor(x => x[i].model)

                }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
do you need further assistance here?