使用Javascript修改复制的EditorTemplates

使用Javascript修改复制的EditorTemplates,javascript,ajax,razor,asp.net-mvc-4,Javascript,Ajax,Razor,Asp.net Mvc 4,我有一个编辑器模板,其中包含一个表行,其中有一个下拉/组合框,用于选择货币。此编辑模板在同一视图上显示多次,用户可以根据需要多次添加这些行 我希望一行下拉列表中的更改反映在同一行的EditorFor(货币汇率)中,因此我添加了onchange html参数: <td> @*@Html.LabelFor(model => model.Currency)*@ @Html.DropDownListFor(model => model.Currency, new

我有一个编辑器模板,其中包含一个表行,其中有一个下拉/组合框,用于选择货币。此编辑模板在同一视图上显示多次,用户可以根据需要多次添加这些行

我希望一行下拉列表中的更改反映在同一行的EditorFor(货币汇率)中,因此我添加了onchange html参数:

<td>
    @*@Html.LabelFor(model => model.Currency)*@
    @Html.DropDownListFor(model => model.Currency, new SelectList(Model.CurrencyList, "Code", "Code"), new { onchange = "updateCurrency(this)" })
    @Html.ValidationMessageFor(model => model.Currency)
</td>
我的问题是

var RateId = "@Html.ClientIdFor(model=>model.Rate)"
具有作为服务器端代码的Html帮助程序。因此,当我查看页面的源代码时,javascript代码被复制(每行一次),所有的var RateId=“@Html.clientdfor(model=>model.Rate)”都指向最近添加的列的EditorFor

可能我试图解决问题的方法是错误的,但是我如何让javascript代码更新所需的字段(即与更改的下拉列表位于同一行的字段)

我相信其中一个问题是编辑器模板上有javasript,但是我如何访问document.getElementById(RateId).value=msg;如果我那样做


提前谢谢:)

想好了。希望它能帮助某人:

我认为:

@Html.DropDownListFor(model => model.Currency, new SelectList(Model.CurrencyList, "Code", "Code"), new { @onchange = "updateCurrency(this, " + @Html.IdFor(m => m.Rate) + ", " + @Html.IdFor(m => m.Amount) + ", " + @Html.IdFor(m => m.Total) + ")" })
在单独的JavaScript文件中:

function updateCurrency(elem, RateId, AmountId, TotalId) {

   var cell = elem.parentNode // to get the <td> where the dropdown was

   var index = rowindex(cell) // get the row number

   // Request the currency's rate:
   $.ajax({

      blah blah blah .........
      (RateId[index - 1]).value = 'retreived value'; // Set the rate field value.

   });

}
function updateCurrency(elem、RateId、AmountId、TotalId){
var cell=elem.parentNode//以获取下拉列表的位置
var index=rowindex(cell)//获取行号
//请求货币汇率:
$.ajax({
胡说八道。。。。。。。。。
(RateId[index-1]).value='retrieved value';//设置rate字段值。
});
}
到目前为止似乎还有效

function updateCurrency(elem, RateId, AmountId, TotalId) {

   var cell = elem.parentNode // to get the <td> where the dropdown was

   var index = rowindex(cell) // get the row number

   // Request the currency's rate:
   $.ajax({

      blah blah blah .........
      (RateId[index - 1]).value = 'retreived value'; // Set the rate field value.

   });

}