我有一个Location
模型和一个Services
模型,使用应用程序的上下文类我可以在位置的 create 方法中对服务模型进行查询,但是如何在绑定的强类型视图的视图中访问这些结果到地点?
namespace LocationApp.Models
{
public class Location
{
public Location()
{
this.ServiceAssignments = new HashSet<ServiceAssignment>();
}
public int id { get; set; }
public string name { get; set; }
public bool active { get; set; }
public virtual ICollection<ServiceAssignment> ServiceAssignments { get; set; }
}
}
namespace LocationApp.Models
{
public class Service
{
public Service()
{
this.ServiceAssignments = new HashSet<ServiceAssignment>();
}
public int id { get; set; }
public string name { get; set; }
public string description { get; set; }
public bool active { get; set; }
public string icon { get; set; }
public virtual ICollection<ServiceAssignment> ServiceAssignments { get; set; }
}
}
public ActionResult Create()
{
using (var db = new LocationAppContext())
{
var serv = (from s in db.Services
where s.active == true
select s).ToList();
if (serv.Count > 0)
{
return View(serv);
}
else
{
return View();
}
}
}