Quantcast
Channel: Internet Explorer Web Development forum
Viewing all articles
Browse latest Browse all 3527

Refresh JQuery Edit Dialog after update

$
0
0

I have a JQuery UI modal dialog which loads an Edit view which saves the edited data in the database. When the view loads for the first time, I click the Edit link which opens the Edit view with the data populated. After Save, the parent page is refreshed with the edited data but when I click the Edit button again and load the Edit dialog, the old values before the Save operation is displayed in the Edit form.

How to load the edited data in the modal dialog?

Code for edit link which opens JQuery UI modal dialog :

$("#lnkEditBook").live("click", function (e) {
                url = $(this).attr('href');

                $(".ui-dialog-title").html("Edit Book");
                $("#dialog-createbook").dialog('open');

                return false;
            });
Controller method for Edit are as follows:
public ActionResult Edit(int id)
        {
            if (context == null)
                context = new BookStoreEntities();

            Book book = context.Books.Where(b => b.Id == id).FirstOrDefault();

            //ViewBag.PublisherList = new SelectList(context.Publishers, "Id", "Name", book.PublisherId);

            BindPublisherDropDown(id);

            return View(book);
        }

        [HttpPost]
        public ActionResult Edit(Book model, FormCollection formCollection)
        {
            if (context == null)
                context = new BookStoreEntities();

            Book book = context.Books.Where(x => x.Id == model.Id).Single<Book>();
            book.Title = model.Title;
            book.Auther = model.Auther;
            book.Price = model.Price;
            book.Year = model.Year;
            //book.PublisherId = int.Parse(formCollection["PublisherList"]);
            book.PublisherId = int.Parse(formCollection["PublisherId"]);
            //book.PublisherId = model.Publisher.Id;
            //book.PublisherId = (int)Session["SelectedPublisherId"];
            context.SaveChanges();

            //ViewBag.PublisherList = new SelectList(context.Publishers, "Id", "Name", book.PublisherId);
            BindPublisherDropDown(model.Id);

            if (ModelState.IsValid)
            {
                ViewBag.SaveStatus = "Book " + book.Title + " updated successfully.";
            }
            else
            {
                ViewBag.SaveStatus = "Error updating book " + book.Title;
            }

            //return View(model);
            //return RedirectToAction("Details", new Book { Id = model.Id });

            return RedirectToAction("Index");

        }



Viewing all articles
Browse latest Browse all 3527

Trending Articles



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