0
我有一个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();
}
}
}
你在视图中显示了什么?你想显示一个服务列表或位置列表? – Shyju
创建视图显示用于创建新位置的表单,我想为每个服务添加复选框列表。因此,您可以将特定服务绑定到某个位置。 – TheWebs
查看我使用编辑器模板的答案 – Shyju