I'm trying to use a button to call the "Edit" action method from a controller named "Students", the following is my code:
<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")';" />' }
]
});
obviously it doesn't work, I tried using Html.ActionLink method and it worked but I need a button not a link. I'm still new at using bootstrap table, can someone help?
Update: forgot to say that the Edit method expects a number to be passed to it, and this number is the item.Id from the foreach loop.
In the onClick event, can you can try this?
'<input type="button" value="Edit" onclick="window.location.href="/Students/Edit/@item.Id""/>'
It will invoke the Edit action in the Students controller.
尝试这个:
<a href='@Url.Action("Edit","Students", new {id = @item.Id})' class='btn btn-default'>Edit</a>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.