views:

1756

answers:

3

Hi,

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


I have these options for a 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 generate the following??

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

I'm not sure if I understand the question right, but you want just the raw URL, based upon an Action Method or something?

Then how about the UrlHelper class?

This previous question on SO discusses this option.

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

Pure.Krome
I don't need the url, I need the onclick...
Ropstah
A: 

It turns out that it is not possible. The Sys.Mvc.AsyncHyperlink.handleClick() function relies on the anchor tag to function correctly. The href specified in the anchor is used to determine which service is called on the server.

I ended up creating a Ajax.ActionLink() and making it invisible (display:none). I know invoke the click using Javascript. jQuery actually (normal invoke: link.click() does not work properly!):

$(link).trigger("click");
Ropstah
A: 

old thread i know, but i am having similar problems. I pretty much understand what you are saying, but how do you get a reference to the anchor link to pass to the jquery? When using Ajax.ActionLink it gives no id for it.

Nik
You can pass an ID with the Attribute parameter when using the Ajax.ActionLink helper...you can also make sure that the Anchor tag is always say the First child tag in a DIV executing the request. This makes it easy to go: $('div#id_of_div:firstchild').trigger('click');. Like the :firstchild selector there are many other selectors which help you 'select' the Anchor at any location inside or outside the div... (outside going like: $('div#id_of_div').parent() and so on...
Ropstah