c# - 循环内的唯一 ID

标签 c# asp.net-mvc razor

如何为@for循环中的每个项目提供不同的ID,以便我可以在jQuery中使用该唯一ID来检索值?

 @for (int i = 0; i < searchList.Count;i++ )
 {
     <label for="one"><input type="checkbox" id="one"/>@searchList[i]</label>
 }

最佳答案

 @for (int i = 0; i < searchList.Count;i++ )
 {
     <label for="one"><input type="checkbox" id="one_@i"/>@searchList[i]</label>
 }

关于c# - 循环内的唯一 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30054739/

相关文章:

c# - Newtonsoft.Json - 忽略 DataContractAttribute

c# - 为特定区域创建 S3 存储桶

c# - .NET中文CultureInfo "zh"不存在?

asp.net-mvc - 无法在 Windows 10 中使用命令行安装网站 msi

c# - 将 MVC 站点母版页转换为 Razor 布局页 - 如何处理代码隐藏?

asp.net-mvc - Multi-Tenancy w/NHibernate+CaSTLe Windsor(单个应用程序,多个数据库)

c# - 在 Html.ActionLink 中包含模型属性的语法是什么?

javascript - 为什么我可以从像 onblur 这样的事件内部调用 JavaScript 函数,但是当我调用 <body> 底部的函数时,它会变成 'undefined' ?

asp.net-mvc - 如何在区域中使用公共(public) _ViewStart?

asp.net-mvc - 与 jquery 选项卡一起使用时,Html.Actionlink 显示错误的 Controller 名称