I am trying to make a MVC website with Ajax call. I have no problem using directly jquery, but when i use @Ajax.ActionLink, i don't get the result i want. Here is my view:
<script type="text/javascript">
function deleteComment(id) {
$.post(
"/Role/AjaxTest",
//{ id: id },
function (data) {
$("#testtarget").html(data);
});
}
</script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
<h2>TITLE</h2>
<p>
@Ajax.ActionLink("Ajax Test", "AjaxTest", "Role", new AjaxOptions{UpdateTargetId="testtarget",HttpMethod = "Get" , InsertionMode = InsertionMode.Replace })
</p>
<table>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.RoleName)
</td>
<td>
<a onclick="deleteComment('@item.RoleId'); return false;" href="#">Delete</a>
@Html.ActionLink("Delete", "Delete", new { id=item.RoleId })
</td>
</tr>
}
</table>
<div id="testtarget">Test Div</div>
and here is my Controler data:
public string AjaxTest()
{
return "Some random text";
}
My Call on Jquery works perfectly and text appears in the div, but my actionlink just redirects me to : localhost/Role/AjaxTest so i just have the message in a bank browser.
Any idea what's wrong here?
Thanks a lot in advance!
jquery.unobtrusive-ajax.min.js
file is being loaded? – Crashaw