title: ASP.NET MVC3 ajax partial view refresh
body: <p>I am facing a problem with ajax updating of div in asp.net mvc3.</p>
  
  <p>I have a View with content</p>
  
  <pre><code>&lt;div id="post_comments"&gt;
     @{Html.RenderPartial("_RefreshComments", Model);}
   &lt;/div&gt;
  &lt;div id="commentForm"&gt;
  @using (Ajax.BeginForm("Details", new { id = Model.Post.PostId }, new AjaxOptions
             {
                HttpMethod = "POST",
                InsertionMode = InsertionMode.InsertAfter, 
                UpdateTargetId = "post_comments"
              }
            ))
  {
  // form content goes here
  &lt;p id="buttons"&gt;
      &lt;input type="submit" value="@Strings.Save" /&gt;
  &lt;/p&gt;
  }
  </code></pre>
  
  <p>This is my partial view</p>
  
  <pre><code>@model Project.Models.Posts.PostDetailsViewModel   
  
  @{ 
      foreach (var c in Model.ApprovedComments)
      { 
          @Html.DisplayFor(x =&gt; c)        
      } 
  }
  </code></pre>
  
  <p>I have a controller </p>
  
  <pre><code>public ActionResult Details(int id, FormCollection form )
  {
      var model = new PostDetailsViewModel(UnitOfWork, id);
      return PartialView("_RefreshComments", model);
  
  }
  </code></pre>
  
  <p>I have following script included in my layout cshtml</p>
  
  <pre><code>&lt;script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>and also </p>
  
  <pre><code>  &lt;appSettings&gt;
      &lt;add key="UnobtrusiveJavaScriptEnabled" value="true" /&gt;
    &lt;/appSettings&gt;  
  </code></pre>
  
  <p>It really works, I am able to add comments, but controller only returns the PartialView, not contained in the layout. I am found <a href="https://stackoverflow.com/questions/4888521/asp-net-mvc3-razor-views-and-partialviews-with-ajax-postbacks">ASP.net MVC3 - Razor Views and PartialViews with Ajax Postbacks</a> but nothing from there helped me. </p>
  
  <p>Does anyone have any ideas?</p>