【发布时间】:2018-02-22 01:50:53
【问题描述】:
我正在尝试使用按钮从名为“Students”的控制器中调用“Edit”操作方法,以下是我的代码:
<script>
$("#table1").bootstrapTable({
columns: [
{ field: 'fn', title: "First Name" }, { field: 'ln', title: "Last Name" }, { field: 'gender', title: "Gender" },
{ field: 'totalmarks', title: "Total Marks" }, { field: "totalcourses", title: "Total Courses Enrolled In" },
{field: 'links', title: "Actions"}
],
data: [
@foreach (var item in Model)
{
int total = ((StudentsController)this.ViewContext.Controller).totc(@item.Id);
@: { fn: '@item.FirstName', ln: '@item.LastName', gender: '@item.Gender', totalmarks: '@item.TotalMarks', totalcourses: '@total',
@: links: '<input type="button" value="Edit" onclick="window.location.href='@Url.Action("Edit","Students")';" />' }
]
});
显然它不起作用,我尝试使用 Html.ActionLink 方法并且它起作用但我需要一个按钮而不是链接。 我还是新手使用引导表,有人可以帮忙吗?
更新:忘了说 Edit 方法需要一个数字传递给它,这个数字是来自 foreach 循环的 item.Id。
【问题讨论】:
-
为什么需要一个按钮?只需将您链接的样式设置为看起来像一个按钮。添加您的 ActionLink 如下:@Html.ActionLink("action", "controller", new { parameterName: value }, new { @class= "btn btn-primary" });
-
这正是我所做的,我使用了一个链接:class="btn btn-default"。对我来说效果很好。
标签: javascript c# html asp.net-mvc-5