在ASP.NET MVC3中,我使用Webgrid来填充数据。我有一个列,我希望该列中的数据具有操作链接。我的表看起来像这样
Roll No | StudentName | Class | Course | |
======================================================
110 | XY | 5 | Science| ViewDetails
我想提供一个指向行中每个ViewDetails的链接,以便移动到所需的操作。同时我想将一个RollNo值传递给该操作。如何实现这一目标。我试过这样的事情。
var grid = new WebGrid(source: Model, canPage: true, rowsPerPage: 10);
grid.Pager(WebGridPagerModes.NextPrevious);
@grid.GetHtml(tableStyle: "grid",
htmlAttributes: new { id = "DataTable" },
headerStyle: "grid-header",
footerStyle: "grid-header",
alternatingRowStyle: "grid-alternating-row",
selectedRowStyle: "grid-selected-row",
rowStyle: "grid-row-style",
columns: grid.Columns(
grid.Column(columnName: "RollNo", header: "RollNo"),
grid.Column(columnName: "StudentName", header: "StudentName"),
grid.Column(columnName: "Class", header: "Class"),
grid.Column(columnName: "Course", header: "Course"),
grid.Column(header: "",
format:item =>
new HtmlString(Html.ActionLink("ViewDetails","Home"))));
答案 0 :(得分:2)
用这种糟糕的语法来做:
grid.Column(
header: "Link",
format: @<text>@Html.ActionLink("ViewDetails", "Home")</text>)
在<text>
块中,您可以使用变量item
来访问当前行:
format: @<text>@Html.ActionLink(item.Text, "Home")</text>
答案 1 :(得分:0)
您可以使用HTML.Raw()
grid.Column(header: "",
format:item =>
HTML.Raw(Html.ActionLink("ViewDetails","Home"))));