Jquery 使用javascript参数作为数组索引
我想在javascript函数中使用一个参数作为razor数组的索引参数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
function loadTemplate(index) {
$("#wellContainer").empty();
var htmldata = @Model.ServiceTemplateList[index].html
$("#wellContainer").append(htmldata);
}
I get当前上下文中不存在名称索引
我做错了什么?从常规的onClick=loadTemplate(1)链接调用
loadTemplate()
function。但是由于这个错误,我无法编译我的代码。你不能那样做。Razor中的代码和语句在页面交付到浏览器和javascript开始工作之前在服务器上进行处理。razor语句不知道此索引,因为它在该阶段中根本不存在。是否仍有在运行时访问该模型的方法?