Click here to Skip to main content
15,903,540 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is code
C#
[HttpPost]
       public ActionResult GetAllCompanies()
       {
            //public IEnumerable<CompanyDetails> GetCars() {
           using (var con = new SqlConnection
            (ConfigurationManager.ConnectionStrings["ConnectionName"].ConnectionString))
           {
               var cmd = new SqlCommand("GetAllCompanies", con);
               cmd.CommandType = CommandType.StoredProcedure;


               try
               {
                   if (con.State != ConnectionState.Open)
                       con.Open();
                   cmd.ExecuteNonQuery();
                   return View();
               }
               finally
               {
                   if (con.State != ConnectionState.Closed)
                       con.Close();
               }
           }
       }


in my .cshtml page

below am not getting in foreach where all the retrived data will come ...


@using (Html.BeginForm())
{
@foreach (var item in )
{
@Html.DisplayFor(modelItem => item.)
@Html.DisplayFor(modelItem => item.)
@Html.DisplayFor(modelItem => item.)
@Html.DisplayFor(modelItem => item.)
@Html.DisplayFor(modelItem => item.)
@Html.ActionLink("Edit", "Edit") |
@Html.ActionLink("Details", "Details") |
@Html.ActionLink("Delete", "Delete")
}
}
Posted

1 solution

OK. You have three approaches:
1) Use an other ORM, not EF. There are plenty of them out there. Besides: why not EF? - stored procedure is not a problem, see this[^].
2) Create a model class for your result set, a generic list based on that class, and fetch all data into that list with legacy ADO.NET tools. Drawback: you will have to fetch all at once, which can grow large depending on your database.
3) Create an IEnumerable on top of DataReader (see this[^]), and pass it to the View as model.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900