I use MVC 3.
With the following code:
@Ajax.ActionLink("CreateUser", "Administration",
new AjaxOptions { HttpMethod = "GET",
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "DialogContainer",
OnComplete = "OpenDialog();" })
I get a javascript error when i click the link:
GET> http://myWebsite.com/Administration/Administration?X-Requested-With=XMLHttpRequest
404 (Not Found) jquery-1.8.2.min.js:2
I the function designated for “OnComplete” is fired and the dialog pops out but not content is return from the controller.
Can you help ?
The 404 error tells you that the page /Administration/Administration does not exist. That is the action method Administration does not exist on the AdministrationController.
Check that the action method “Administration” exists.
The overload you are using is ActionLink(string linkText, string actionName, AjaxOptions ajaxOptions).
The query string X-Requested-With=XMLHttpRequest is not required to solve this issue.
By default Microsoft Ajax and jQuery use a header to signify that a request originates in JavaScript. MVC makes allowances for the fact that not all environments allow custom headers (X-Requested-With is a custom error) to be sent with a request, by allowing the header value to be sent as a Query String parameter.