无论我在做什么,当我在表单中有两个按钮时,即使其中一个是CLEARLY不是提交按钮而另一个是提交类型输入,它们都会提交表单。我有这样的代码:
<form method="POST">
<tr class="record">
/* This one submits */
<td><button onclick="location.href='editStudent.cshtml?id=@row.No'">Edit record</button></td>
/* And so does this one */
<td><input type="submit" value="Delete" /></td>
</tr>
</form>
我知道我不应该创建一个表格中间表,但这不是重点。请告诉我,我做错了什么,因为我一直在解决这个问题太久了。
答案 0 :(得分:0)
正如您在此处http://www.w3schools.com/tags/tag_button.asp所见,您应该定义按钮元素的type属性以避免意外行为
所以,如果你不想搞乱javascript,你可以试试这个
<button type="button" onclick="location.href='editStudent.cshtml?id=@row.No'">Edit record</button>