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.