I have an Ajax action link which requests a string in the control method. I want to insert that string into the hyperlink attribute. Can I specify the attribute field of the target id element?
& lt; Img id = "CHANGE-MY-SRC" src = ViewData ["src"] & gt; & Lt;% = Ajax.ActionLink ("Change IMG Source", "Action Change", New Ajax Option () UpdateTargetId = "CHANGE-MY-SRC"})%>
Change public string actions () {ViewData ["src"] = "something new"; Return return }
Default behavior for Ajax assistants will not support this. However, you can create a custom JavaScript handler which returns the Ajax request, and then the attribute is used to inject it into the value
Create a simple JavaScript file (load it in the master page For example) and add this function:
// creates an Ajax on Complemental Handler which will inject the /// inhr HTML function insteadAttributeInjector (attributeName) instead of specified Feature function in the attribute (ajaxContext) {if (ajaxContext.get_updateTarget ()! == faucet) {ajaxContext.get_updateTarget () [attributeName] = ajaxContext.get_data (); } // Important: press default behavior! return false;
Then, when your Ajax link is created:
Ajax External Link ("Change IMG Source", "Action Change", New Ajax Option () {UpdateTargetId = "Change-MySRC", On-Confessed = "Create Detectivity Injector ('src')"}
Disclaimer: I have not been able to give this a test, but I did the same thing with Ajax assistants. Post in my comment for the answer if you have problems and I am happy to help you! If this Works, so do me too in the comments If you have a source (), you can see the AjaxContext.cs file in the Microsoft MVMeXScript project for a complete list of properties that you can access from on-the-compiled handlers < / P>
Comments
Post a Comment