title: MVC4 link between view and controller
body: <p>I'm writing my first MVC app (MVC4). A lot of it's been generated using the excellent Razor tools in VS2010, but now I've run into a wall and I feel I don't understand something fundamental.</p>
  
  <p>In my app, </p>
  
  <ul>
  <li>a User can have access to many Clients.</li>
  <li>I have a Client Controller and View.</li>
  <li>I have a User Controller and View (expanded version of the simple
  membership's UserProfile, populated using User.Identity).</li>
  </ul>
  
  <p>What I want to do is let the user edit a client's details and ALSO edit their own account details on the same page.</p>
  
  <p>I've tried using Html.Partial to add the UserProfile view to the Client view, but it bombs out trying to pass the UserProfile view the Client model.</p>
  
  <p>How do I make the Client view call the UserProfile <em>controller</em> so it can read the User.Identity and return the correct UserProfile view?</p>
  
  <p>I tried making it a viewmodel with both the client and userprofile classes attached, and doing it all on the one screen, but it refused to send values to the controller on submit.</p>
  
  <p>Client view:</p>
  
  <pre><code>@model MyProject.Client
  &lt;div&gt;
   @Html.Partial("_AcctDetailsPartial")
  &lt;/div&gt;
  &lt;div&gt;
   @using (Html.BeginForm())
  {
  .
  .
  .
  @Html.HiddenFor(model =&gt; model.ClientID)
  {
  .
  .
  .    
   &lt;client fields&gt;
  {
  .
  .
  .    
   &lt;div class="form-actions"&gt;
        &lt;button type="submit" name="ButtonName" value="Company" class="btn blue"&gt;&lt;i class="icon-ok"&gt;&lt;/i&gt; Save&lt;/button&gt;
         &lt;button type="button" class="btn"&gt;Cancel&lt;/button&gt;
   &lt;/div&gt;
  }
  
  &lt;/div&gt;
  </code></pre>
  
  <p>UserProfile View:</p>
  
  <pre><code>@model Surecall.UserProfile
  
  &lt;div style="height: auto;" id="accordion1-1" class="accordion collapse"&gt;
  @using (Html.BeginForm())
  {
          &lt;h3 class="form-section"&gt;Personal Info&lt;/h3&gt;
          &lt;label class="control-label"&gt;First Name&lt;/label&gt;
          @Html.TextBoxFor(m =&gt; m.FirstName, new { @class = "m-wrap span8", @id="FirstName" })
          &lt;label class="control-label"&gt;Last Name&lt;/label&gt;
          @Html.TextBoxFor(m =&gt; m.Surname, new { @class = "m-wrap span8" })
          &lt;label class="control-label"&gt;Phone Number&lt;/label&gt;
          @Html.TextBoxFor(m =&gt; m.Mobile, new { @class = "m-wrap span8" })
          &lt;label class="control-label"&gt;Email&lt;/label&gt;
          @Html.TextBoxFor(m =&gt; m.Email, new { @class = "m-wrap span8" })
          &lt;label class="control-label"&gt;Position&lt;/label&gt;
          @Html.TextBoxFor(m =&gt; m.Occupation, new { @class = "m-wrap span8" })
              &lt;label class="control-label"&gt;Interests&lt;/label&gt;
          @Html.TextBoxFor(m =&gt; m.Interests, new { @class = "m-wrap span8" })
          &lt;div class="form-actions"&gt;
              &lt;button type="submit" name="SaveLoginDetails" value="SaveUser" class="btn green"&gt;&lt;i class="icon-ok"&gt;&lt;/i&gt; Save&lt;/button&gt;
              &lt;button type="button" class="btn"&gt;Cancel&lt;/button&gt;
          &lt;/div&gt;
  }
  
  &lt;/div&gt; 
  </code></pre>