Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem is that you are not using view models. You have just defined some <code>CustomerSitesListViewModel</code> class in which you have stuffed your domain models as properties which is inappropriate for the requirements of this particular view. </p> <p>So the first thing to do is to define a clean view model. You said that you need to access in your partial properties for both the customer and the customer site. So there must be some relation between them.</p> <p>Let's start by defining this view model:</p> <pre><code>public class SiteViewModel { public string AddressLine1 { get; set; } } public class CustomerViewModel { public string Name { get; set; } public SiteViewModel Site { get; set; } } </code></pre> <p>and finally the main view model:</p> <pre><code>public class CustomerSitesListViewModel { public IEnumerable&lt;CustomerViewModel&gt; Customers { get; set; } } </code></pre> <p>now let's move on to the controller:</p> <pre><code>public ActionResult Index() { // TODO: query repositories and map the domain objects // they returned to the actual view model. Can't help much // here as I don't know how are your domain models and repositories // organized var viewModel = new CustomerSitesListViewModel { Customers = ... }; return View(viewModel); } </code></pre> <p>and then the main view which will be strongly typed to <code>CustomerSitesListViewModel</code>:</p> <pre><code>&lt;%= Html.DisplayFor(x =&gt; x.Customers) %&gt; </code></pre> <p>and finally we need to define an editor template which will be rendered automatically for eqch element of the Customers collection. It should be located in <code>~/Views/Shared/DisplayTemplates/CustomerSitesListViewModel.ascx</code>:</p> <pre><code>&lt;%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl&lt;CustomerSitesListViewModel&gt;" %&gt; &lt;%= Html.DisplayFor(x =&gt; x.Name) %&gt; &lt;%= Html.DisplayFor(x =&gt; x.Site.AddressLine1) %&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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