I have an cshtml page with the following code:

@Ajax.ActionLink("My ajax link", "ActionName", new { id = Model.Id }, new AjaxOptions { InsertionMode = InsertionMode.Replace, UpdateTargetId = "myDivId", HttpMethod = "GET" })
<div id="myDivId"></div>

When I debug the project, the source code of the page is:

<a data-ajax="true" data-ajax-method="GET" data-ajax-mode="replace" data-ajax-update="#myDivId" href="">My ajax link</a>

I just don't understand why the "href" property is empty. The controller is the same that executes the actual page and has an action called "ActionName"... can anyone help please?

有帮助吗?

解决方案 2

Ok, so I answer myself to help anyone else with this issue: The route you specify in the ajaxlink MUST be registered in "RouteConfig.cs" or "Global.asax"...

context.MapRoute(
            "MyRoute",
            "Test/Hello/{id}",
            new
            {
                Controller = "ControllerName",
                action = "ActionName"
            }
        );

其他提示

Try this:

@Ajax.ActionLink("My ajax link", "ActionName","ControllerName",null, new { id = Model.Id }, new AjaxOptions { InsertionMode = InsertionMode.Replace, UpdateTargetId = "myDivId", HttpMethod = "GET" })
<div id="myDivId"></div>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top