3

I have a <table> that has a header row. I'm trying to add an item under the header row, but there seems to be no way to describe this intent to the ActionLink function.

InsertionMode.InsertBefore with the header row's ID specified as the update target just puts the row on the top of the table, Replace replaces the header of the table, and InsertAfter actually puts a new row inside the header row -- which is obviously invalid.

Is there any way to specify that I want to append some HTML after or before a tag?

Thanks in advance.

Rei Miyasaka
  • 7,007
  • 6
  • 42
  • 69

2 Answers2

4

AFAIK there is no way to achieve such behavior with only properties of the AjaxOptions class. One way would be to subscribe for the OnSuccess method and do the insertion manually:

@Ajax.ActionLink("click me", "someAction", new AjaxOptions { OnSuccess = "success" })

and the success function:

<script type="text/javascript">
    function success(result) {
        $('table').after('th').append(result);
    }
</script>

or if you are using MicrosoftAjax you need to call the get_data method to fetch the returned result from the ajax call:

function success(result) {
    $('tableid').after('th').append(result.get_data());
}
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
0

Use Jquery.

$("tableid").after("<th></th>").append("whatever");
T4u
  • 291
  • 2
  • 8
  • Yeah of course I could do this in jquery using `$.ajax()`, but my question is how to do this using Ajax.ActionLink in MVC. – Rei Miyasaka Apr 23 '11 at 01:55