ASP.NET MVC Ajax: how to update the Ajax.ActionLink itself

I have a page that displays a list box with items from a large number of items, each with a boolean property representing the Enabled and Disabled states.

I need to provide the user with a link for each list item and the link text should show the opposite status (so if the item is enabled, the link text should show "Disabled").

When a user clicks a link for a disabled, the corresponding link text for the item should be changed to Enable (and vice versa).

I would like to NOT reload the entire list for every click, just the text of the ActionLink itself, so my question is:

Is it possible to update only the ActionLink itself when the user clicks on the link, or can I handle this with custom javascript?

+2


source to share


2 answers


As I recall, you can add HTML attributes to the "a" tag by adding an anonymous class as the last parameter for most overloads.

At the top of my head, it could be written like this:

Html.ActionLink("Name", "Action", "Controller", new { @class = 'updateId' });

      

(You can do this with an identifier, which is preferred over the class - if not just use a unique class name to avoid updating multiple elements.)



Then you can use javascript to access the "updateId" class and change the internal html.

In case of jQuery:

$("a.updateId").html("NewName");

      

+1


source


This can be done using a custom control contained in the item being updated. A solution record can be found here . No custom client-side scripting required.



0


source







All Articles