database - Two tables one view ASP MVC -
i need help. trying show locations of device belonging specific project.
on projects page have button goes google map. projects have projects model , controller. i've got 2 tables, table containing location of device , project table. want display device locations belonging project on google map. google maps part working , managed show device locations on 1 map, problem can't seem link devices project. need on how achieve this.
in location table ive got foreign key projects table. many-to-onerelation. project can have multiple devices, device can linked 1 project. have defined relation follows in location model:
[belongsto("projectid")] public project project { { return _project; } set { _project = value; } }
in location controller use following code(theres more moment not relevant):
public actionresult index() { return view(devicelocation.findall()); }
this lists locations in location table. need list locations projectid = id of projects table. i'm coming php/mysql , there join 2 tables. how achieve asp mvc?
you should read on linq , how use query data.
something should help:
public actionresult index() { return view(devicelocation.where(d=> d.projectid == myprojectid)); }
Comments
Post a Comment