Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 使用javascript参数作为数组索引_Jquery_Asp.net Mvc_Razor - Fatal编程技术网

Jquery 使用javascript参数作为数组索引

Jquery 使用javascript参数作为数组索引,jquery,asp.net-mvc,razor,Jquery,Asp.net Mvc,Razor,我想在javascript函数中使用一个参数作为razor数组的索引参数 function loadTemplate(index) { $("#wellContainer").empty(); var htmldata = @Model.ServiceTemplateList[index].html $("#wellContainer").append(htmldata); } I get当前上下文中不存在名称索引 我做错了什么?从常规的onClick=loadTemp

我想在javascript函数中使用一个参数作为razor数组的索引参数

function loadTemplate(index) {
    $("#wellContainer").empty();
    var htmldata = @Model.ServiceTemplateList[index].html
    $("#wellContainer").append(htmldata);
}
I get
当前上下文中不存在名称索引


我做错了什么?

从常规的onClick=loadTemplate(1)链接调用
loadTemplate()
function。但是由于这个错误,我无法编译我的代码。你不能那样做。Razor中的代码和语句在页面交付到浏览器和javascript开始工作之前在服务器上进行处理。razor语句不知道此索引,因为它在该阶段中根本不存在。是否仍有在运行时访问该模型的方法?