c# - Add data from two tables in one view MVC 4 -
i trying add data 2 different table in 1 view. here somne code: code of viewmodel
public class productindexdata { public ienumerable<order> orders { get; set; } public ienumerable<magnet> magnets { get; set; } public ienumerable<map> maps { get; set; } public ienumerable<portrait> portraits { get; set; } public ienumerable<tablet> tablets { get; set; } public ienumerable<other> others { get; set; } }
code of controller:
public actionresult index() { productindexdata products = new productindexdata(); products.magnets = (from o in db.magnets select o).tolist(); return view(products); }
code of view:
@model list<svlaseris.productindexdata> @{ viewbag.title = "product"; } <h2>product</h2> <table> @foreach (var item in model) { foreach(svlaseris.models.magnet magnet in item) { <tr> <td> @html.displayfor(modelitem => magnet.count) </td> <td> @html.displayfor(modelitem => magnet.model) </td> <td> @html.displayfor(modelitem => magnet.color) </td> <td> @html.displayfor(modelitem => magnet.fullprice) </td> <td> @html.actionlink("edit", "edit", new { }) | @html.actionlink("details", "details", new { }) | @html.actionlink("delete", "delete", new { }) </td> </tr> } } </table>
after compilation ve got error in second foreach cycle in view says not contait definition getenumerator. looking :/
seems forgot specify want iterate on item.magnets
property:
foreach(svlaseris.models.magnet magnet in item.magnets)
Comments
Post a Comment