views:

21

answers:

1

Is it possible to create Ajax.ActionLink which has instead of text, the whole DIV?

I'd like to map div on Ajax.ActionLink

Thx in advance

+1  A: 

I don't think that this will work using the standard MVC Ajax scripts. I believe that the MVC javascript is created to use an <a> element by default. On a different note, embedding a div tag within an <a> is not valid XHTML. What are you trying to achieve?

Using Jquery is probably the easiet way you want to go. As an example:

<div onclick="SomeAjaxFunction()">some div content</div>

function SomeAjaxFunction()
{
  $.get('<%= Url.Action("SomeAction", "InSomeController") %>', function(data) {
      $('.result').html(data); // assuming a partial view
      alert('Load was performed.');
});
}

However, if you are dead set on using MS Ajax, to work with divs, you need to possibly look at the Sys.Mvc.MvcHelpers._asyncRequest function and do some of your own re-wrapping to make it usable. I have not tried or tested this, so use at your own risk. (Stick with the Jquery, there is far better help and support available.)

Ahmad
Thx for your answer, You probably are right. JQUery in this example would be better. I just wanted to get know how to do this in MS Ajax. I know jQuery is great, but with Ajax's Helpers from MS it is really easy to create Ajax links, Ajax forms etc...
Simon

related questions