删除行中的WebGrid与使用Visual Studio 2012在MVC3复选框 [英] Delete row in webgrid with checkboxes in MVC3 using Visual Studio 2012
问题描述
我是新来MVC3。我有$ C $的CD中,我显示数据与复选框一个的WebGrid的应用程序。我试图找出如何发送一个特定的行ID控制器的操作方法,当我点击一个复选框。任何帮助AP preciated。
I am new to MVC3. I have coded an application in which I display data into a webgrid with checkboxes. I am trying to find out how to send a particular row id the controller action method when I click on a checkbox. Any help appreciated.
推荐答案
这是一个完整的例子,我有一个包含删除链接,使用Ajax调用服务器上的一个动作的最后一列一的WebGrid。上Ajax请求完成时,相应的行被从表中删除。在 MvcHtmlString
用来span标记注入列。它包含要从表中删除一个id值随后被用于标识行
This is a complete example where I have a WebGrid with the last column containing a "Remove" link that uses Ajax to call an action on the server. On completion of the Ajax request, the corresponding row is removed from the table. The MvcHtmlString
is used to inject a span tag into the column. It contains an id value that is subsequently used to identify the row to be removed from the table.
<div id="ssGrid">
@{
var grid = new WebGrid(canPage: false, canSort: false);
grid.Bind(
source: Model,
columnNames: new[] { "Location", "Number", "Protection", "Methodology" }
);
}
@grid.GetHtml(
tableStyle: "webGrid",
headerStyle: "header",
alternatingRowStyle: "alt",
columns: grid.Columns(
grid.Column("Location", "Location"),
grid.Column("Number", "Number"),
grid.Column("Protection", "Protection"),
grid.Column("Methodology", "Methodology"),
grid.Column(
format: (item) =>
new MvcHtmlString(string.Format("<span id='ssGrid{0}'>{1}</span>",
item.SecondarySystemId,
@Ajax.RouteLink("Remove",
"Detail", // route name
new { action = "RemoveSecondarySystem", actionId = item.SecondarySystemId },
new AjaxOptions {
OnComplete = "removeRow('ssGrid" + item.SecondarySystemId + "')"
}
)
)
)
)
)
)
</div>
<script>
function removeRow(rowId) {
$("#" + rowId).closest("tr").remove();
}
</script>
这篇关于删除行中的WebGrid与使用Visual Studio 2012在MVC3复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!