Ajax.ActionLink中的动态更新目标ID [英] dynamic update target id in Ajax.ActionLink
问题描述
我在网格中有此代码,并且我想要操作链接的UpdateTargetId,每行要更改的div ID
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>
我想为网格中的每一行更改UpdateTarget id,例如将id附加到它,然后将相同的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.
推荐答案
NetDev,
我想我知道你在做什么.您想遍历某些项目并创建div和链接,如下所示:
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>
您有一个好的开始,但是您是否查看了呈现的HTML?我认为是这样:<div id ="Result"+"<%=o.Id%>"></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>
没有按照您认为的去做.基于该代码的呈现的HTML看起来很糟糕. <div id="Result"+"1"></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>
尝试将动态div ID命名更新为此:
Try updating your dynamic div id naming to this instead:
<div id="Result<%=o.Id%>"></div>
然后应该以HTML格式显示为<div id="Result1"></div>
Which should then render out in HTML as <div id="Result1"></div>
这篇关于Ajax.ActionLink中的动态更新目标ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!