1
  public class EmployeeController : Controller
{
    //
    // GET: /Employee/

    public ActionResult Details(int id)
    {
        EmployeeContext employeeContext = new EmployeeContext();

        Employee employee = employeeContext.Employees.SingleOrDefault(x => x.EmployeeId == id);
        return View(employee);
    }

}   

//here i am getting only one row with respect to id .. how can i get the whole rows from the table ?and how can i view that on the view page?

1
  • so you want all rows in your table to be displayed on another page? like the Index.cshtml page? Commented Mar 24, 2016 at 13:10

1 Answer 1

2

To return the whole table, just select the whole table instead of filtering.

Employee[] allEmployees = employeeContext.Employees.ToArray();

To show them in a view, just have the model type for your view be an array instead of just a singular Employee. Basically just make the model Employee[]. Then you can just loop over the model.

@model Employee[]
@foreach(var employee in Model)
{
    // do something interesting
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.