質問

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