Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing Ajax gives stale results
    primarykey
    data
    text
    <p><strong>EDIT</strong></p> <p>My <code>Ajax</code> form gets correct <code>Id</code> to update a content and a <code>replace</code> option. Submitting is by clicking <code>&lt;input type="submit" value="submit!" /&gt;</code>.</p> <p><code>Problem</code>: When I clicked on <code>submit</code> I didn't see any update. Second trial gave the expected result. When I refreshed the page the lost record (first hit was successful) was on spot.</p> <p><strong>Model</strong></p> <pre><code>[Serializable] public abstract class AbstractEntity { public Guid Id { get; set; } public DateTime LastModified { get; set; } } [Serializable] public class Product : AbstractEntity { public Product() { this.Attachments = new HashSet&lt;Attachment&gt;(); } public String Title { get; set; } public String Commentary { get; set; } public DateTime PlacedOn { get; set; } public String User { get; set; } public ICollection&lt;Attachment&gt; Attachments { get; set; } } [Serializable] public class Attachment { public String MimeType { get; set; } public String Description { get; set; } public String Filename { get; set; } } </code></pre> <p><strong>Controller</strong></p> <pre><code>[HandleError] public class ProductController : Controller { private readonly IDocumentSession documentSession; public ProductController(IDocumentSession documentSession) { this.documentSession = documentSession; } public ActionResult ListRecent() { return View(ListAll()); } [Audit, HttpPost] public ActionResult Delete(Guid id) { documentSession.Delete&lt;Product&gt;(documentSession.Load&lt;Product&gt;(id)); documentSession.SaveChanges(); return PartialView("ProductsList", ListAll()); } [Audit, HttpPost] public ActionResult Create(Product product) { if(ModelState.IsValid) { documentSession.Store(product); documentSession.SaveChanges(); } return PartialView("ProductsList", ListAll()); } private IEnumerable&lt;Product&gt; ListAll() { return documentSession.Query&lt;Product&gt;().ToArray(); } } </code></pre> <p><strong>Views ('scriptless')</strong></p> <blockquote> <p>Layout</p> </blockquote> <pre><code>&lt;head&gt; &lt;title&gt;@ViewBag.Title&lt;/title&gt; &lt;link href="@Url.Content("~/Content/stylesheets/normalize.css")" rel="stylesheet" type="text/css" /&gt; &lt;link href="@Url.Content("~/Content/stylesheets/site.core.css")" rel="stylesheet" type="text/css" /&gt; &lt;script src="@Url.Content("~/Scripts/jquery-1.7.2.js")" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="main-wrapper"&gt; &lt;div id="header"&gt;[@Html.ActionLink("List", "ListRecent", "Product")]&lt;/div&gt; &lt;div id="content"&gt;@RenderBody()&lt;/div&gt; &lt;/div&gt; &lt;/body&gt; </code></pre> <blockquote> <p>ListRecent.cshtml</p> </blockquote> <pre><code>@model IEnumerable&lt;lamp.DomainLayer.Entities.Product&gt; @{ ViewBag.Title = "ListRecent"; var options = new AjaxOptions { InsertionMode = InsertionMode.Replace, UpdateTargetId = "productsList" }; } &lt;h2&gt;List&lt;/h2&gt; @Html.Partial("ProductsList", Model) @using(Ajax.BeginForm("Create", "Product", options)) { &lt;fieldset&gt; &lt;p&gt; &lt;label class="autoWidth"&gt;Title&lt;/label&gt; @Html.Editor("Title") @Html.ValidationMessage("Title") &lt;/p&gt; &lt;p&gt; &lt;label class="autoWidth"&gt;Commentary&lt;/label&gt; @Html.TextArea("Commentary") @Html.ValidationMessage("Commentary") &lt;/p&gt; @* Some fields I have omitted.. *@ &lt;input type="submit" value="submit" /&gt; &lt;input type="reset" value="clear" /&gt; &lt;/fieldset&gt; } </code></pre> <blockquote> <p>ProductsList.cshtml</p> </blockquote> <pre><code>@model IEnumerable&lt;lamp.DomainLayer.Entities.Product&gt; @{ var options = new AjaxOptions { InsertionMode = InsertionMode.Replace, UpdateTargetId = "productsList" }; } &lt;div id="productsList"&gt; @foreach(var p in Model) { &lt;div class="productCard"&gt; &lt;p class="title"&gt;&lt;strong&gt;Title&lt;/strong&gt;: @p.Title&lt;/p&gt; &lt;p class="author"&gt;&lt;strong&gt;User&lt;/strong&gt;: @p.User&lt;/p&gt; &lt;p class="date"&gt;&lt;strong&gt;Placed on&lt;/strong&gt;: @idea.PlacedOn.ToShortDateString()&lt;/p&gt; &lt;p class="link"&gt;@Html.ActionLink("details", "Details", "Product")&lt;/p&gt; &lt;p class="link"&gt; @using(Ajax.BeginForm("Delete", "Product", new { id = p.Id }, options)) { &lt;input type="submit" value="you!" /&gt; } &lt;/p&gt; &lt;/div&gt; } &lt;/div&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload