dynamic update target id in Ajax.ActionLink

2019-02-25 23:06发布

问题:

i have this code in a grid and I want to have UpdateTargetId of the action link, div id to be changed for each row

<%: Ajax.ActionLink("Select", "GetCodes", "BvIndex", new { id = o.Id }, new AjaxOptions { UpdateTargetId ="Result"})%>
 <div id ="Result"></div>

I tried this but i didn't get it

    <%: Ajax.ActionLink("Select", "GetCodes", "BvIndex", new { id = o.Id }, new AjaxOptions { UpdateTargetId ="Result"+o.Id})%>
<div id ="Result"+"<%=o.Id%>"></div>

I want to have UpdateTarget id to be changed for each row in the grid, like appending id to it, and then assigning the same id to div in which i have to show the result.

回答1:

NetDev,

I think I know what you are getting at. You want to loop through some items and create divs and links like so:

<link1 targetID="Result1"/>
<div id="Result1">Some Stuff</div>
<link1 targetID="Result2"/>
<div id="Result2">Some Stuff</div>
<link1 targetID="Result3"/>
<div id="Result3">Some Stuff</div>

What you have is a good start, but have you looked at your rendered HTML? I think that this: <div id ="Result"+"<%=o.Id%>"></div>

is not doing what you think its doing. The rendered HTML based on that code would look like...well bad. <div id="Result"+"1"></div>

Try updating your dynamic div id naming to this instead:

<div id="Result<%=o.Id%>"></div>

Which should then render out in HTML as <div id="Result1"></div>