如何在 kendo-ui 网格中制作 actionlink/url.action
How to make actionlink/url.action in kendo-ui grid
目前我在 asp.net mvc5 项目中工作 kendo-ui 网格...
我想知道是否可以在网格按钮所在的网格中进行操作link或url.action....
<script>
$(document).ready(function () {
var projectdata = "http://localhost:xxxx",
$("#grid").kendoGrid({
dataSource: dataSource,
pageable: true,
toolbar: ["create"],
scrollable: false,
sortable: true,
groupable: true,
columns: [
{ field: "Name", title: "Task Name", width: "170px" },
{ field: "Status", title: "Status", width: "110px" },
{ field: "IsActive", title: "Active", width: "50px" },
{ command: ["edit", "delete", "Setting", "Task"], title: " ", width: "150px" }
],
editable: "popup"
});
});
</script>
我必须在命令字段中更改 "Setting" 并在其中放置操作 link 或 url.action。
创建自定义命令模板:
<script id="command-template" type="text/x-kendo-template">
<a class="k-button k-grid-even" href=" @Html.ActionLink("Setting", "Home", "ProjectContr", new { orderId = id },null)">Even</a>
</script>
并将其添加为您的专栏的一部分
columns: [
{ field: "Name", title: "Task Name", width: "170px" },
{ field: "Status", title: "Status", width: "110px" },
{ field: "IsActive", title: "Active", width: "50px" },
{ command: ["edit", "delete", "Setting", "Task"], title: " ", width: "150px" },
{ template: kendo.template($("#command-template").html())}]
知道只有当代码是 cshtml 文件的一部分时这才有效,因为类似的文件需要被解析。 link 如果分离到 js 文件将失败。
如果您正在使用 asp.net mvc 为什么不使用 razor 代码?
举个例子,希望对你有帮助
@(Html.Kendo().Grid<YourObject>()
.Name("grid")
.TableHtmlAttributes(new { style = "min-height: 331px;" })
.ToolBar(t => t.Create())
.Columns(columns =>
{
columns.Template(@<text></text>).ClientTemplate("<div style=\"text-align:center\">" +
"<a href=\"" + Url.Action("Test", new { id = "#=Id#"}) + "\"><i style=\"padding-right: 8px;\" title=\"Setting\" class=\"fa fa-pencil fa-lg\"></i></a>" +
"</div>").Width(60).Title("");
columns.Bound(c=>c.Id).Hidden(true);
columns.Bound(c=>c.Name);
columns.Bound(c => c.Status);
columns.Bound(c => c.IsActive).ClientTemplate("<div style=\"text-align:center\">" +
"# if(Active) {#" +
"yes" +
"#} else {#" +
"no" +
"#}#" +
"</div>").Width(15);
})
.Sortable()
.Filterable()
.Pageable()
.DataSource(dataSource => dataSource
.Ajax()
.Model(model => model.Id(m => m.Id))
.Read(read => read.Action("Read", "YourObject"))
)
).Filterable()
)
目前我在 asp.net mvc5 项目中工作 kendo-ui 网格...
我想知道是否可以在网格按钮所在的网格中进行操作link或url.action....
<script>
$(document).ready(function () {
var projectdata = "http://localhost:xxxx",
$("#grid").kendoGrid({
dataSource: dataSource,
pageable: true,
toolbar: ["create"],
scrollable: false,
sortable: true,
groupable: true,
columns: [
{ field: "Name", title: "Task Name", width: "170px" },
{ field: "Status", title: "Status", width: "110px" },
{ field: "IsActive", title: "Active", width: "50px" },
{ command: ["edit", "delete", "Setting", "Task"], title: " ", width: "150px" }
],
editable: "popup"
});
});
</script>
我必须在命令字段中更改 "Setting" 并在其中放置操作 link 或 url.action。
创建自定义命令模板:
<script id="command-template" type="text/x-kendo-template">
<a class="k-button k-grid-even" href=" @Html.ActionLink("Setting", "Home", "ProjectContr", new { orderId = id },null)">Even</a>
</script>
并将其添加为您的专栏的一部分
columns: [
{ field: "Name", title: "Task Name", width: "170px" },
{ field: "Status", title: "Status", width: "110px" },
{ field: "IsActive", title: "Active", width: "50px" },
{ command: ["edit", "delete", "Setting", "Task"], title: " ", width: "150px" },
{ template: kendo.template($("#command-template").html())}]
知道只有当代码是 cshtml 文件的一部分时这才有效,因为类似的文件需要被解析。 link 如果分离到 js 文件将失败。
如果您正在使用 asp.net mvc 为什么不使用 razor 代码?
举个例子,希望对你有帮助
@(Html.Kendo().Grid<YourObject>()
.Name("grid")
.TableHtmlAttributes(new { style = "min-height: 331px;" })
.ToolBar(t => t.Create())
.Columns(columns =>
{
columns.Template(@<text></text>).ClientTemplate("<div style=\"text-align:center\">" +
"<a href=\"" + Url.Action("Test", new { id = "#=Id#"}) + "\"><i style=\"padding-right: 8px;\" title=\"Setting\" class=\"fa fa-pencil fa-lg\"></i></a>" +
"</div>").Width(60).Title("");
columns.Bound(c=>c.Id).Hidden(true);
columns.Bound(c=>c.Name);
columns.Bound(c => c.Status);
columns.Bound(c => c.IsActive).ClientTemplate("<div style=\"text-align:center\">" +
"# if(Active) {#" +
"yes" +
"#} else {#" +
"no" +
"#}#" +
"</div>").Width(15);
})
.Sortable()
.Filterable()
.Pageable()
.DataSource(dataSource => dataSource
.Ajax()
.Model(model => model.Id(m => m.Id))
.Read(read => read.Action("Read", "YourObject"))
)
).Filterable()
)