ASP.NET MVC - How to get Ajax 'onclick' for a specific action (I need for Ajax.ActionLink, what Url.RouteUrl does for Html.ActionLink)

REVISION
I want to add an onclick to the element that handles the Ajax request, not just the route-redirect.


I have these parameters for the route url.

Html.ActionLink(params)
Url.RouteUrl(params) 'returns JUST ActionUrl

      

So I can go like

<div onclick="javascript:location.href('<%=Url.RouteUrl(params)%>')"></div>

      


But how do I create the following

<div onclick="Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: 'WorkorderDetails' });"></div>

      

0


a source to share


2 answers


It turns out that this is impossible. The Sys.Mvc.AsyncHyperlink.handleClick () function relies on the anchor tag to work properly. The href specified in the binding is used to determine which service is invoked on the server.

I ended up creating Ajax.ActionLink () and making it invisible (display: none). I know you are clicking the click using Javascript. jQuery actually (normal invoke: link.click () is not working correctly!):



$(link).trigger("click");

      

+4


a source


I'm not sure if I understood the question correctly, but do you only want the original url based on the action method or something?

Then what about the UrlHelper class ?



This previous SO question discusses this option.

As I said, I'm not sure I understood the question 100%.

0


a source







All Articles