ITsolutionWizard
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
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)
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
do you need further assistance here?