0

The issue:

I need to reload a div (with a table inside) after a "delete" operation, like deleting an user from my database, and then refreshing the table with current users without refreshing whole page.

Each row of the table haves a delete link button, that raises post action to delete.

1st solution to reload a div: I found out this solution that works fine. https://stackoverflow.com/a/1721623/1199167

The problem:

Works fine only the 1st time, when I launch it for the 2nd time, jquery seems to crash and doesnt work anymore, the links that I use to launch my function seems to be stranger to the jquery source code..

There is no exception, there is no alert at all... so it becomes hard to say what is goin on...

I read somewhere that could be a problem that I don't have my .js files on the rendered partial page, but I returned whole page as a view (not partial) and replaced from the first div, and I got the same result...

Some code:

My jquery post:

    var url = "@Url.Action("Delete")";

    $.ajax({
        url: url,
        type: 'POST',
        dataType: 'json',
        data: someData,
        success: function (data) {
            $(".DivToUpdate").load('@Url.Action("Index")');
        }
    });

//pretty standar example...

My delete method works fine.

nothing important here...

My Index [get] method:

[HttpGet]
    public ActionResult Index()
    {
        ViewData.Model = SomeDataToShow();

        if (Request.IsAjaxRequest())  //I found out this on another post.
        {
            return PartialView(); //works ok.
        }

        return View();
    }

My Index html:

1) javascript code to make this post. (could be a problem if this js is on the rendered page result?) 2) some non-important html 3) foreach on the table rows... every link on rows is rendered with this:

   <a href="#" id="@item.IdCliente" class="BotonEliminar">[E]</a>

...as an alternative, I tryed to use @html.ActionLink... doesn't work either :(

the end.

Ideas welcome! Thanks.

Community
  • 1
  • 1
Yogurtu
  • 2,656
  • 3
  • 23
  • 23
  • 1
    You are going to have to show us your ACTUAL code (relevant portions of JS and HTML) for us to know how to help you. And, when the page stops working, is there anything showing in the debug console? – jfriend00 May 05 '14 at 23:38
  • I used f12 console option from chrome, i can't see anything on breakpoints, exceptions or log :(... / I will update question whit some code. tnks – Yogurtu May 05 '14 at 23:41
  • 1
    It sounds like the buttons on your refreshed view aren't bound to your event handler anymore. How are you binding that jQuery code to your delete buttons? – James Mason May 06 '14 at 00:01
  • It's something like that!!! i found out what is happening here... I have my jquery files on my _layout page, when I see source code on first time, i can see .Js includes correctly... but when Ajax executed, those includes are gone! cause only reload partial page... how can avoid this? if im only chargin one div?? why all partials are gone? – Yogurtu May 06 '14 at 00:03

1 Answers1

0

This problem is caused by other issue.

I found out that at the first moment, if you right click source code, you can see js includes. After performing jquery post, js includes are gone!, only remains Html rendered code.

I can't find the way to do a jquery reload, so im going to start a new thread with the proper answer.

Solution might be found here, when posted: https://stackoverflow.com/q/23484549/1199167

Thanks for the help.

Community
  • 1
  • 1
Yogurtu
  • 2,656
  • 3
  • 23
  • 23