i have a big beginner Problem i think! I try to make a ASP.NET MVC 5 Applikation, the application should store Suppliers in a database table, in seperate table it should store SalesOrders. In the View, when i click on details of the Supplier, all details should be load, but also all SalesOrders where for this Supplier should be load too. i've tried this way without result.
ModelBase Contains an prop ID only.
The Classes
public class SalesOrder : ModelBase
{
public string ordertitle { get; set; }
public Supplier Supplier { get; set; }
}
public class Supplier : ModelBase
{
public string CompanyName { get; set; }
public string ContactPerson { get; set; }
public string Phone { get; set; }
public string Street { get; set; }
public string Zip { get; set; }
public string City { get; set; }
public int Discount { get; set; }
}
The ViewModel
public class SalesOrderViewModel
{
public Supplier Supplier { get; set; }
public List<SalesOrder> SalesOrder { get; set; }
}
The Controller
public ActionResult SupplierSalesOrders(int id)
{
var supplier = _context.Suppliers.Single(s => s.Id == id);
var salesorder = _context.SalesOrders.ToList().Where(s => s.Supplier == supplier);
SalesOrderViewModel viewModel = new SalesOrderViewModel
{
Supplier = supplier,
SalesOrder = salesorder.ToList()
};
return View(viewModel);
}
The View
@model NETwork.Models.SalesOrderViewModel
@foreach(var sales in Model)
{
@Html.LabelFor(model => model.SalesOrder)
}
sorry for the loooong question.
What ive done wrong?
best regards
Lars