title: MVC How to pass in a relational ID from a model into a partial view with a different model
body: <p>I want to add a create function to my page, it has a buildings page and a rooms page however depending on which building is chosen rooms corresponding to its ID are shown. I have that completed but I wanted to add a create function to add more rooms when in a specific building. I have all the required code for creating/inserting in a partial view but I need to pass in relational value without having to put it in myself. Similar to this action link:</p>
  
  <pre><code>@Html.ActionLink("Edit", "Edit", **new { id=item.Id }**)
  </code></pre>
  
  <p>Here is my room page: </p>
  
  <pre><code>@model TerminalHost.Models.buildingInfo
  
  @{
  ViewBag.Title = "Home Page";
  }
  &lt;h3&gt;Rooms in: @Model.buildingName&lt;/h3&gt;
  &lt;ol class="round"&gt;
  
  &lt;li class="one"&gt;
      &lt;h5&gt;Please begin creating your network structure:&lt;/h5&gt; &lt;button id="modal-opener"&gt;Add a new room&lt;/button&gt;
  
  &lt;/li&gt;
  &lt;li class="two"&gt;
  
  &lt;/li&gt;
  &lt;/ol&gt;
  @*rooms that are specific to a building are shown here*@
  @Html.Partial("rooms", Model.roomId)
  
  &lt;div id="Modal" title="room Details"&gt;
  @Html.Partial("roomForm", new TerminalHost.Models.roomInfo())
  &lt;/div&gt;
  </code></pre>
  
  <p>my displayed rooms partial view:</p>
  
  <pre><code>@model IEnumerable&lt;TerminalHost.Models.roomInfo&gt;
  
  &lt;div class="Container"&gt;
  @foreach (var item in Model)
  {&lt;div class="Box"&gt;
      &lt;div&gt;
          &lt;h4 class="Heading"&gt;@item.roomName&lt;/h4&gt;
          &lt;h4 class="Heading"&gt;@item.roomNumber&lt;/h4&gt;
          &lt;p&gt;@item.roomDesc1&lt;/p&gt;
          &lt;p&gt;@item.roomDesc2&lt;/p&gt;
          &lt;p&gt;@item.roomDesc3&lt;/p&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  }
  &lt;/div&gt;
  </code></pre>
  
  <p>my roomForm partial view:</p>
  
  <pre><code>@model TerminalHost.Models.roomInfo
  
  @{
  ViewBag.Title = "Create";
  }
  
  &lt;h2&gt;Create&lt;/h2&gt;
  
  @using (Html.BeginForm("roomForm", "Home"))
  {
  @Html.AntiForgeryToken()
  @Html.ValidationSummary(true)
  
  &lt;fieldset&gt;
      &lt;legend&gt;roomInfo&lt;/legend&gt;
  
      &lt;div class="editor-label"&gt;
          @Html.LabelFor(model =&gt; model.roomNumber)
      &lt;/div&gt;
      &lt;div class="editor-field"&gt;
          @Html.EditorFor(model =&gt; model.roomNumber)
          @Html.ValidationMessageFor(model =&gt; model.roomNumber)
      &lt;/div&gt;
      ....
      //Here I would like the building Id to be passed automatically from the buildingInfo model which is being called in the rooms view
      &lt;div class="editor-label"&gt;
          @Html.LabelFor(model =&gt; model.buildingId)
      &lt;/div&gt;
      &lt;div class="editor-field"&gt;
          @Html.EditorFor(model =&gt; model.buildingId)
          @Html.ValidationMessageFor(model =&gt; model.buildingId)
      &lt;/div&gt;
      &lt;p&gt;
          &lt;input type="submit" value="Create" /&gt;
      &lt;/p&gt;
  &lt;/fieldset&gt;
  }
  @section Scripts {
  @Scripts.Render("~/bundles/jqueryval")
  </code></pre>
  
  <p>This is the model that I'm using to store data with:</p>
  
  <pre><code>public class buildingInfo
  {
      public int Id { get; set; }
      public int buildingNumber { get; set; }
      public String buildingName { get; set; }
      public String buildingDesc1 { get; set; }
      public String buildingDesc2 { get; set; }
      public String buildingDesc3 { get; set; }
  
      public virtual ICollection&lt;roomInfo&gt; roomId { get; set; }
  }
  </code></pre>
  
  <p>Here is the roomInfo model:</p>
  
  <pre><code>public class roomInfo
  {
      public int Id { get; set; }
      public int roomNumber { get; set; }
      public String roomName { get; set; }
      public String roomDesc1 { get; set; }
      public String roomDesc2 { get; set; }
      public String roomDesc3 { get; set; }
      public int buildingId { get; set; }
  
      //public virtual ICollection&lt;rackInfo&gt; rackId { get; set; }
  }
  </code></pre>
  
  <p>If anymore information is needed please ask and I will provide it.</p>