Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8164255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:16:36+00:00 2026-06-06T19:16:36+00:00

EDIT My Ajax form gets correct Id to update a content and a replace

  • 0

EDIT

My Ajax form gets correct Id to update a content and a replace option.
Submitting is by clicking <input type="submit" value="submit!" />.

Problem: When I clicked on submit 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.

Model

[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<Attachment>();
    }
    public String Title { get; set; }        
    public String Commentary { get; set; }
    public DateTime PlacedOn { get; set; }
    public String User { get; set; }
    public ICollection<Attachment> Attachments { get; set; }
}

[Serializable]
public class Attachment {
    public String MimeType { get; set; }
    public String Description { get; set; }
    public String Filename { get; set; }
}

Controller

[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<Product>(documentSession.Load<Product>(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<Product> ListAll() {
        return documentSession.Query<Product>().ToArray();
    }
}

Views (‘scriptless’)

Layout

<head>
    <title>@ViewBag.Title</title>        
    <link href="@Url.Content("~/Content/stylesheets/normalize.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/stylesheets/site.core.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery-1.7.2.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>
</head>
<body>
    <div id="main-wrapper">
        <div id="header">[@Html.ActionLink("List", "ListRecent", "Product")]</div>
        <div id="content">@RenderBody()</div>
    </div>        
</body>

ListRecent.cshtml

@model IEnumerable<lamp.DomainLayer.Entities.Product>
@{ 
    ViewBag.Title = "ListRecent";
    var options = new AjaxOptions {
        InsertionMode = InsertionMode.Replace,
        UpdateTargetId = "productsList"        
    };
}

<h2>List</h2>

@Html.Partial("ProductsList", Model)

@using(Ajax.BeginForm("Create", "Product", options)) {
    <fieldset>
        <p>
            <label class="autoWidth">Title</label>
            @Html.Editor("Title")
            @Html.ValidationMessage("Title")
        </p>
        <p>
            <label class="autoWidth">Commentary</label>
            @Html.TextArea("Commentary")
            @Html.ValidationMessage("Commentary")
        </p>
        @* Some fields I have omitted.. *@

        <input type="submit" value="submit" />
        <input type="reset" value="clear" />

    </fieldset>
}

ProductsList.cshtml

@model IEnumerable<lamp.DomainLayer.Entities.Product>
@{
    var options = new AjaxOptions {
        InsertionMode = InsertionMode.Replace,
        UpdateTargetId = "productsList"
    };
}

<div id="productsList">
    @foreach(var p in Model) {
        <div class="productCard">
            <p class="title"><strong>Title</strong>: @p.Title</p>
            <p class="author"><strong>User</strong>: @p.User</p>
            <p class="date"><strong>Placed on</strong>: @idea.PlacedOn.ToShortDateString()</p>
            <p class="link">@Html.ActionLink("details", "Details", "Product")</p>
            <p class="link">
                @using(Ajax.BeginForm("Delete", "Product", new { id = p.Id }, options))  {                
                    <input type="submit" value="you!" />
                }
            </p>
        </div>
    }
</div>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T19:16:37+00:00Added an answer on June 6, 2026 at 7:16 pm

    Ok. Darin was right! I found out that changing my controller code to this one:

    private IEnumerable<Product> ListAll() {
        return documentSession
           .Query<Product>()
           .Customize((x => x.WaitForNonStaleResults()))
           .ToArray();
    }
    

    fixes everything.

    .Customize((x => x.WaitForNonStaleResults()))

    is the solution!

    Thanks everyone!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an edit form that uses an ajax form to submit to the
i have a form with input type=file. it submits using ajax (plugin jquery form
EDIT: iam using ajax to load text in my content that is why onload
I am unable to determine which form submit button is clicked during an Ajax
I want to submit a form whenever checkboxes are clicked (I already have ajax
I'm using TinyMCE to edit a Ajax loaded form. When I post the form
I am getting null values of Model on Controller when I submit Ajax.BeginForm form.
The ajax feature is on route http://mysite/playlist-edit/3 Javascript: $(#applySort).click(function(){ var list = $(#sortable).sortable('toArray'); $.post({
I'm going to edit an ImageField using jquery ajax,after searching I found out I
EDIT: I see why it doesn't run twice. I have the Ajax.BeginForm() call inside

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.