Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

Ajax Update works only first time

$
0
0

Dear All

I have problem with update records in PartialView with Ajax. I have View with call @Html.Action ("_PartialView", "Controller", new { id = OrderId }) and PartialView with Ajax Form

@model IEnumerable<WebMartin.Models.OrderExecutionRemark>

@{
    AjaxOptions ajaxOpts = new AjaxOptions
    {
        UpdateTargetId = "orderdisplayremark",
        Url = Url.Action("OrderRemarkDelete", "OrderExecution"),
        HttpMethod = "POST"
    };
}

@ViewBag.Po

@if (Model.Any())
{
    <table id="orderdisplayremark"><thead><tr><th>Worker</th><th>Date</th><th>Remark</th><th></th></tr></thead><tbody>
            @foreach (var remark in Model)
            {<tr><td>@remark.UserName</td><td>@remark.OrderRemarkDate.ToString("yyyy-MM-dd")</td><td>@remark.OrderRemarkText</td><td>
                        @using (Ajax.BeginForm(ajaxOpts))
                        {
                            @Html.Hidden("remarkid", remark.OrderRemarkId)<input type="submit" value="Delete" />
                        }</td></tr>
            }</tbody></table>
}

and Controller

        [HttpPost]
        public PartialViewResult OrderRemarkDelete(int remarkid)
        {
            OrderExecutionRemark oer = db.OrderExecutionRemarks.Find(remarkid);
          /*  db.OrderExecutionRemarks.Remove(oer);
            db.SaveChanges(); */
            ViewBag.Po = oer.OrderRemarkId;

            return PartialView("_OERemarkPartial", db.OrderExecutionRemarks.Where(p => p.OrderId == oer.OrderId).ToList());
        }

        [HttpGet]
        [ChildActionOnly]
        public PartialViewResult _OERemarkPartial(int id = 0)
        {
            return PartialView(db.OrderExecutionRemarks.Where(p => p.OrderId == id).ToList());
        }        

Problem

update works only first time, after - not. I have to refresh page before push "Delete" button again. How solve it? I thought I'd use RedirectToAction(View) but I am using this PartialView in three different Views.

Thank you in advance for all answers.

Regards

Krzysztof


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>