OrderBy a sequence and showing in seperate tables

There is probably a simple answer for this question but I couldn't find it.

I am trying to create a list (ordered by Type) from this model:

public partial class FarmDetail
public System.Guid Id { get; set; }
public int FarmId { get; set; }
public int Type { get; set; }
public string Name { get; set; }
public string Value { get; set; }

public virtual Farm Farm { get; set; }

My controller is;

public ActionResult MachineInfo(int? id)
if (id == null)
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
FarmDetail farmdetail = db.FarmDetails.Where(x => x.FarmId == id).OrderBy(x => x.Type).FirstOrDefault();

if (farmdetail == null)
return HttpNotFound();
return View(farmdetail);

And my View is;

@model FarmManagement.v2.Models.FarmDetail

ViewBag.Title = "Machine Info";
Layout = "~/Views/Shared/_Layout.cshtml";

Machine Info


@for (int i = 0; i < Model.Farm.FarmDetails.Count(); i++)


@Html.DisplayNameFor(model => model.Name)

@Html.DisplayNameFor(model => model.Type)

@Html.DisplayNameFor(model => model.Value)

@Html.DisplayNameFor(model => model.Farm.LicenseKey)

@Html.DisplayFor(modelItem => modelItem.Farm.FarmDetails.ElementAt(i).Name)

@Html.DisplayFor(modelItem => modelItem.Farm.FarmDetails.ElementAt(i).Type)

@Html.DisplayFor(modelItem => modelItem.Farm.FarmDetails.ElementAt(i).Value)

@Html.DisplayFor(modelItem => modelItem.Farm.LicenseKey)

@Html.ActionLink("Back to Farms List", "Index")

I know that my problem is with the .FirstOrDefault() part in my controller. It is obviously ordering the fist row only and other rows remain unsorted. But I couldn't find any other alternative.

What I want to do is to have 6 different table in View;

etc. How can I do this? Thanks!
Asked: February 18, 2016 by administrator