title: ASP.net MVC3 - Razor Views and PartialViews with Ajax Postbacks
body: <p>I have been very unsuccessful in getting this to work!</p>
  
  <p>In a view...</p>
  
  <pre><code>@model Project.Models.Account.ForgotPasswordModel
  
  @{
      ViewBag.Title = "Forgot Password";
  }
  
  &lt;h2&gt;ForgotPassword&lt;/h2&gt;
  
  &lt;span id='@ViewBag.ReplaceID'&gt;
      @Html.Partial("_ForgotPasswordUserNameAjax", ViewData.Model)
  &lt;/span&gt;
  </code></pre>
  
  <p>I render this partialView...</p>
  
  <pre><code>@model Project.Models.Account.ForgotPasswordModel
  
  @{
      this.Layout = null;
  }
  
  @using (Ajax.BeginForm("ForgotPassword", new AjaxOptions() { UpdateTargetId = ViewBag.ReplaceID, InsertionMode = InsertionMode.InsertAfter }))
  {
      @Html.ValidationSummary(true, "Forgot Password was unsuccessful. Please correct the errors and try again.")
      &lt;div id="login" class="box"&gt;
              &lt;fieldset&gt;
              &lt;h2&gt;Account Information&lt;/h2&gt;
              &lt;div class="inside"&gt;
                  &lt;div class="editor-label"&gt;
                      @Html.LabelFor(m =&gt; m.Username)
                  &lt;/div&gt;
                  &lt;div class="editor-field"&gt;
                      @Html.TextBoxFor(m =&gt; m.Username)
                      &lt;br /&gt;
                      @Html.ValidationMessageFor(m =&gt; m.Username)
                      &lt;br /&gt;
                  &lt;/div&gt;
  
                  &lt;p&gt;
                      &lt;input type="submit" value='Submit' /&gt;
                  &lt;/p&gt;
              &lt;/div&gt;
          &lt;/fieldset&gt;
      &lt;/div&gt;   
  }
  </code></pre>
  
  <p>And this controller action...</p>
  
  <pre><code>[HttpPost]
          public PartialViewResult ForgotPassword(ForgotPasswordModel model)
          {
  
              if (String.IsNullOrEmpty(model.Username))
              {
                  ModelState.AddModelError("Username", ForgotPasswordStrings.USER_NAME_REQUIRED);
              }
              else
              {
                  bool isGood = false;
                  model.Question = this._security.ValidateUserNameGetSecurityQuestion(model.Username, out isGood);
  
                  if (!isGood)
                  {
                      ModelState.AddModelError("Username", ForgotPasswordStrings.USER_NAME_INVALID);
                  }
  
              }
              PartialViewResult retVal = null;
              if (ModelState.IsValid)
              {
  
                  retVal = PartialView("ForgotPasswordAnswerAjax", model);
              }
              else
              {
                  retVal = PartialView("_ForgotPasswordUserNameAjax", model);
              }
  
              return retVal;
  
          }
  </code></pre>
  
  <p>Yet, every single time, the view only returns the PartialView, not contained in the layout.(So just my PartialView is on the screen.  Nothing else.)  I've tried a few things I've found online...
  <a href="http://www.compiledthoughts.com/2011/01/aspnet-mvc-razor-partial-views-with.html">http://www.compiledthoughts.com/2011/01/aspnet-mvc-razor-partial-views-with.html</a>
  http://stackoverflow.com/questions/4655365/mvc3-submit-ajax-form</p>
  
  <p>But nothing has fixed this issue.  I've changed the InsertionMode to all values with no change.  I've changed the @Html.Partial to a code block like
  @{
  Html.RenderPartial("_ForgotPasswordUserNameAjax", ViewData.Model);
  }.</p>
  
  <p>That doesn't work...</p>
  
  <p>I'm running out of ideas (and patience)!</p>
  
  <p>Please help!</p>