문제

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