I'm using MVC, I would like to pass a row index (razor variable) to a JS.

我正在使用MVC,我想将行索引(razor变量)传递给JS。

 @for (int i = 0; i < Model.Topics.Count(); i++)
                {
                    <tr id="row-@i"> 

                        <td class="IsReadOnly">@Html.TextBoxFor(model => model.Topics[i].NumberOfNoDifficulltySet, new { @readonly = "readonly", @class = "SubjectTB", @onchange = "CheckNoDiff(this);" })</td>

                    </tr>
                }

the js function is CheckNoDiff(this) - I would like to pass the @i parameter - that is the row index as an argument to the js. How do I do that? and how do I receive the parameter value on js?

js函数是CheckNoDiff(这个) - 我想传递@i参数 - 这是行索引作为js的参数。我怎么做?以及如何在js上接收参数值?

Any help is most welcome - Regards, Lior.

任何帮助都是最受欢迎的 - 问候,Lior。

1 个解决方案

#1


If you can use JQuery.data() then you can just add an attribute to your text box like so:

如果您可以使用JQuery.data(),那么您只需在文本框中添加一个属性,如下所示:

data-assigned-id="@i"

Then remove the parameter from the CheckNoDiff function and within the CheckNoDiff function you can access the value like so:

然后从CheckNoDiff函数中删除参数,在CheckNoDiff函数中,您可以像这样访问值:

var id= $(this).data('assigned-id');

更多相关文章

  1. 如何使用jQuery在GET请求中传递参数
  2. ABP(现代ASP.NET样板开发框架)系列之21、ABP展现层——Javascrip
  3. 为什么括号用于包装javascript函数调用? [重复]
  4. javascript 构造函数中的属性与原型上属性优先级的比较
  5. 在javascript中调用带有双参数()的函数
  6. ajax请求中URL和参数的编码问题
  7. Objective-C方法/函数调用。 (来自javascript示例)
  8. Javascript函数的4种调用方法详解
  9. JavaScript(ES5)使用保留字作函数名

随机推荐

  1. android junit (一)
  2. 自定义控件之View原理与使用
  3. android基础知识12:android自动化测试06—
  4. Android FrameLayout子view居中(左居中,右
  5. Android定义圆角背景方面的介绍
  6. 【Android】应用程序启动过程源码分析
  7. 【译】Google官方推出的Android架构组件
  8. Linux kernel起来后Android启动过程
  9. Android的Activity屏幕切换动画-左右滑动
  10. android位图颜色模式的问题