如何将razor变量传递给js
16lz
2021-01-22
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');
更多相关文章
- 如何使用jQuery在GET请求中传递参数
- ABP(现代ASP.NET样板开发框架)系列之21、ABP展现层——Javascrip
- 为什么括号用于包装javascript函数调用? [重复]
- javascript 构造函数中的属性与原型上属性优先级的比较
- 在javascript中调用带有双参数()的函数
- ajax请求中URL和参数的编码问题
- Objective-C方法/函数调用。 (来自javascript示例)
- Javascript函数的4种调用方法详解
- JavaScript(ES5)使用保留字作函数名