I have this code that works.
public class HelloWorldController : Controller
{
UAStagingEntities db = new UAStagingEntities();
public ActionResult Index(int? id)
{
var depot = db.CSLA_DEPOT.Where(c => c.DEPOT_ID == id.Value);
return View(depot.ToList());
}
}
What I don't know how to do is display a view with results from two queries. How would I create the view to show both depot and address? and how would I code the return statement?
public class HelloWorldController : Controller
{
UAStagingEntities db = new UAStagingEntities();
public ActionResult Index(int? id)
{
var depot = db.CSLA_DEPOT.Where(c => c.DEPOT_ID == id.Value);
var Address = db.CSLA_ADDRESS.Where(a => a.CSLA_DEPOT.DEPOT_ID == id.Value);
return View(depot.ToList());
}
}
EDIT *
I added this model
namespace CustomerCareMVC.Models
{
public class CSLA_StagingModel
{
public List<CSLA_DEPOT> depots { get; set; }
public List<CSLA_ADDRESS> addresses { get; set; }
}
}
And added this method in the controller
public ActionResult ShowAllTables()
{
var model = new CSLA_StagingModel()
{
depots = db.CSLA_DEPOT.Where(c => c.DEPOT_ID == 10065),
addresses = db.CSLA_ADDRESS.Where(a => a.CSLA_DEPOT.DEPOT_ID == 10065),
};
return View(model);
}
I get squiggly line under these two lines
depots = db.CSLA_DEPOT.Where(c => c.DEPOT_ID == 10065),
addresses = db.CSLA_ADDRESS.Where(a => a.CSLA_DEPOT.DEPOT_ID == 10065),
with this error message
Error 1 Cannot implicitly convert type 'System.Linq.IQueryable' to 'System.Collections.Generic.List'. An explicit conversion exists (are you missing a cast?) C:\CustCareMVC\CustomerCareMVC\CustomerCareMVC\Controllers\HelloWorldController.cs 59 26 CustomerCareMVC