title: Associate PartialView to model of the page
body: <p>I have a situation I can't solve alone... I have this object:</p>
  
  <pre><code>public class Service
  {
      ...
      public Configuration Conf{get; set;}
      ...
  }
  
  public class Configuration 
  {
      ...
      public List&lt;Gateway&gt; Gateways{get; set;}
      ...
  }
  </code></pre>
  
  <p>Now I have a page to create a new service and I want to add runtime (client-side) a partial view. 
  I have a page that accept as model the Service class.. and a partial view that have the gateway as model..
  Everything seems to work..</p>
  
  <pre><code>@model ObjectModel.Entities.Configurations.Service
  ... 
  
  @section scripts {
      &lt;script type="text/javascript"&gt;
          function loadPartial(event) {
              event.preventDefault();
              event.stopPropagation();
  
              var $div = $(event.target).closest(event.data.divContainer),
                  url = $(this).data('url'), model = event.data.model;
  
              $.post(url, function (model) {
                  $div.prepend(model);
              });
          }
  
          $('#link_add_gateway').live('click', { divContainer: "#new_gateway", model: @Html.Raw(Json.Encode(Model)) }, loadPartial);
      &lt;/script&gt;
  }
  
  ...
  
  &lt;div id="new_gateway"&gt;           
      &lt;a id="link_add_gateway" class="cursor_pointer"
          data-url='@Url.Action("RenderGateway", "Configuration")'&gt;Aggiungi gateway&lt;/a&gt;
  &lt;/div&gt;
  
  &lt;input type="submit" value="Create" class="btn btn-default" /&gt;
  </code></pre>
  
  <p>And here the controller:</p>
  
  <pre><code> //EDIT: Now service is valorized here too..
   public ActionResult RenderGateway(Service service)
      {
          Gateway g = new Gateway();
          service.Configuration.Gateways.Add(g);  
          return PartialView("~/Views/_Partials/Gateway/Edit.cshtml", g);
      }
  
   [HttpPost]
   public ActionResult Create(Service service)
   {
       //Still nothing
   }
  </code></pre>
  
  <p><strong>Here the problem</strong>:
  Service has no gateway valorized.. I think is correct, but I don't know how to solve it! I would like to associate the model of the partial view to the model of the page. 
  How can I do?</p>
  
  <p>thank you</p>
  
  <p>UPDATE: 
  <img src="https://i.stack.imgur.com/ickQA.png" alt="enter image description here">
  <img src="https://i.stack.imgur.com/54LoG.png" alt="enter image description here"></p>
  
  <pre><code>public class Configuration
  {
      [XmlElement(ElementName = "gateway")]
      public GatewaysList Gateways { get; set; }
  
      public Configuration()
      {
          this.Gateways = new GatewaysList();
      }
  }
  
  [Serializable]
  public class GatewaysList : List&lt;Gateway&gt;
  {
      public Gateway this[int gatewayId]
      {
          get
          {
              return this.Find(g =&gt; g.GatewayId == gatewayId);
          }
      }
  }
  </code></pre>