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();
}
}
}