Avaloth Oath Avaloth Oath - 27 days ago 10
ASP.NET (C#) Question

Ajax.ActionLink takes to a different Page MVC 4.5 Visual studio 2015

i checked all possible stackoverflow and asp.net questions about this subject and couldnt solve my problem.
As the title says my Ajax.ActionLink Redirects to a new page instead of replacing the div i selected. i have loaded all necessary packages
see my code below:
in my Bundles i have this:

bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.validate*",
"~/scripts/jquery.unobtrusive-ajax"));


In Bottom of _Layout page

@Scripts.Render("~/bundles/lib")
@Scripts.Render("~/bundles/jqueryval")
@RenderSection("scripts", required: false)


View

@Ajax.ActionLink("New User", "New", "Person", new AjaxOptions
{
UpdateTargetId = "userTable",
HttpMethod = "GET",
InsertionMode = InsertionMode.Replace,
OnFailure = "Something unexpected has occured"
},new {@class = "btn btn-primary"})

<div id="usersTable">
@Html.Partial("_UserTable")
</div>

@section scripts {...} // Some code to load the table on existing partial that is beeing rendered


New action in Person controller

public PartialViewResult New()
{
var person = new Person();
return PartialView("_UserForm", person);
}


PLEASE HELP i have been going on this for days now and honestly i have tried almost everything posted out there.

Edit 1: As a response to jquery.unobtrusive-ajax.js is not loaded correctly, or perhaps being overwritten i have included the browser scripts as they are loaded on the page

<script src="/Scripts/jquery-3.1.1.js"></script>
<script src="/Scripts/bootstrap.js"></script>
<script src="/scripts/bootbox.js"></script>
<script src="/Scripts/respond.js"></script>
<script src="/scripts/datatables/jquery.datatables.js"></script>
<script src="/scripts/datatables/datatables.bootstrap.js"></script>
<script src="/scripts/toastr.js"></script>
<script src="/Scripts/jquery.validate.js"></script>
<script src="/Scripts/jquery.validate.unobtrusive.js"></script>

Answer

Instead of this

bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                "~/Scripts/jquery.validate*",
                "~/scripts/jquery.unobtrusive-ajax"));

shouldn't it be this?

bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                "~/Scripts/jquery.validate*",
                "~/Scripts/jquery.unobtrusive-ajax.js"));

The .js file extension is missing.

Comments