我有一个显示WebGrid的剃须刀网页。当用户单击操作列中的视图时,我需要将该行的ID传递给JavaScript函数,该函数将显示一个对话框。
唯一起作用的onclick函数是CreateWather。尝试调用传入行ID的onclick函数之一时,未调用JavaScript函数。
@{
ViewBag.Title = "Home Page";
Layout = "~/Views/Shared/_Layout.cshtml";
<style type="text/css">.grid { width: 100%; }</style>
}
<div id='OpenDilog'></div>
<div style="width:100%;">
@{
WebGrid grid = new WebGrid(Model);
@grid.GetHtml(
tableStyle: "grid",
fillEmptyRows: false,
mode: WebGridPagerModes.All,
firstText: "<< First",
previousText: "< Prev",
nextText: "Next >",
lastText: "Last >>",
columns: new[] {
grid.Column("task_id",header: "ID"),
grid.Column("task_name",header: "Name"),
grid.Column("client"),
grid.Column("ftp_server"),
grid.Column("task_id", header: "Action", canSort:false,
format: @<text>
@Html.Raw("<img src='/Content/images/view.png' title='Transfers' onclick='ViewTransfers(" + item.task_id + ")' />")
<a href='#' onclick='ViewTransfers(" + task_id + ");'>Edit</a>
<a href='#' onclick='CreateWatcher();'>Create</a>
</text>
)
})
}
</div>
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css"/>
<link href="@Url.Content("~/Content/themes/base/jquery-ui.css")" rel="stylesheet" type="text/css"/>
<script src="@Url.Content("~/Scripts/jquery-ui-1.12.1.min.js")" type="text/javascript"></script>
<script type="text/javascript">
function CreateWatcher() {
var div = $("#OpenDilog");
div.load("/Home/Create", function() {
div.dialog({
modal: true,
width: 500,
height: 400,
title: "Add New Watcher",
resizable: false
});
});
}
function ViewTransfers(W_ID) {
var div = $("#OpenDilog");
div.load("/Home/View?taskId=" + W_ID, function () {
div.dialog({
modal: true,
width: 500,
height: 400,
title: "View Transfers",
resizable: false
});
});
}
</script>
我尝试使用Html.raw和h ref调用,但是它们不起作用。它知道函数带有参数。