Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing parameterized list to view in MVC using Entity Framework
    primarykey
    data
    text
    <p>In a MVC project am trying to create a view which has the Title from a parent table and the subsequent list below it from its related Child table.</p> <p>I pulled the tables into the project using Entity Framework and in the controllers namespace created the follwing Viewmodel:</p> <pre><code>public class ServicesViewModel { public ServicesViewModel(List&lt;ServiceGroup&gt; servicegroups, List&lt;Service&gt; services) { this.ServiceGroups = servicegroups; this.Service = services; } public List&lt;ServiceGroup&gt; ServiceGroups { get; set; } public List&lt;Service&gt; Service { get; set; } } </code></pre> <p>Then in the controller Actionresult I did this:</p> <pre><code> public ActionResult Index() { var servicegroups = _db.ServiceGroupSet.ToList(); var services = _db.ServiceSet.ToList(); return View(new ServicesViewModel(servicegroups,services)); } </code></pre> <p>..And in the View did this:</p> <blockquote> " %> <p>Other html code etc..</p> </blockquote> <pre><code>&lt;% foreach (var m in Model.ServiceGroups) { %&gt; &lt;strong&gt;&lt;ul&gt; &lt;%= m.ServiceGroupName %&gt;&lt;/ul&gt;&lt;/strong&gt; &lt;% foreach (var item in Model.Service) { %&gt; &lt;li&gt; &lt;%= item.ServiceDescription %&gt;&lt;/li&gt; &lt;% } %&gt; &lt;% } %&gt; </code></pre> <p>It all wires up ok but runs ALL child records for each parent record. I have not figured how to put that parameter which filters into the view.</p> <p>I tried a linq query in the controller but can't seem to find the foreign key field in the intellisense.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload