3

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

I'd like to map div on Ajax.ActionLink

GEOCHET
  • 21,119
  • 15
  • 74
  • 98
Simon
  • 2,329
  • 4
  • 30
  • 49

1 Answers1

2

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
  • 22,657
  • 9
  • 52
  • 84
  • 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 Jul 23 '10 at 13:36