【发布时间】:2016-07-19 06:03:08
【问题描述】:
$("body").on("click", "#ActionButton", function (e) {
//set current select index
currentBook = $(this).attr("data-bookId");
//set title
$("#BookAction .modal-title").text('@Model[currentBook].BookName');
//get list of current book forms
@{List<XLEZ.Models.DataModels.FormModel> CurrentFormsList = Model[currentBook].FormList;}
swap('FillNewData', true);// collapse fill new data list if expanded
$("#FillNewData").empty();
@for (int k = 0; k < CurrentFormsList.Count; k++)
{<text>
var html = "<li onClick=\"SubmitForm('@CurrentFormsList[k].FormLink','@CurrentFormsList[k].FormHideExtraValue','@Model[currentBook].FormActionLink')\" class=\"list-group-item bg-grey-300\" > @Html.Raw(CurrentFormsList[k].FormName) </li>";
$(html).appendTo("#FillNewData");</text>
}
});
我正在使用上面的代码通过模型中的数据提交表单。问题是我想在页面加载完毕并且用户做出选择后执行此操作。但是剃刀代码在文档准备好之前呈现,当我单击此按钮时,模型索引 0 上的数据将加载到此脚本中。无论如何我可以在这个函数中循环遍历模型吗?
【问题讨论】:
-
您不能将 JavaScript 变量传递给 Razor 服务器端代码。
-
@Satpal:这个问题有什么解决方案吗?
标签: javascript jquery asp.net-mvc razor asp.net-mvc-5