Frage

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?

War es hilfreich?

Lösung 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"
            }
        );

Andere Tipps

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>
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top