HTTP 404 with Ajax.ActionLink

I have a problem solving 404 error:

The default route in Global.asax.cs:

routes.MapRoute(
       "Default", 
       "{controller}/{action}/{id}",
       new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );

VideoController.cs:

[HttpPost]
public ActionResult Save(int id)
{
   try
   {
     return Json(new
     {
       ID = "0"
     });
   }
   catch
   {
     return new HttpStatusCodeResult(418, "I'm a teapot");
   }
}

ActionLink in my opinion, Create.cshtml:

@Ajax.ActionLink("GoSave", "Save", "Video", new { id = 1 },
        new AjaxOptions { OnFailure = "Error", OnSuccess = "Saved", 
                          HttpMethod = "POST" })

The actionlink URL displays as expected: / Video / Save / 1

When I click on the link, I get 404.

What I do not see?

+5
source share
2 answers

I am sure that you are missing the inclusion script:

<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>

AJAXify Ajax.ActionLink POST GET . 404, script, GET, , GET, "".

FireBug, : GET POJ Ajax.

+11

...

NuGet, " jQuery Ajax".

enter image description here

.

enter image description here

, , , , :

@Scripts.Render("~/Scripts/jquery.unobtrusive-ajax.min.js") 

_Layout.cshtml

+1

All Articles