每个按钮都在ASP中提交[重复]

时间:2022-11-24 09:08:58

This question already has an answer here:

这个问题在这里已有答案:

Whatever I am doing, when i have two buttons in a form, even if one of them is CLEARLY not a submit button and the other one is submit type input, always both of them submit the form. I have piece of code like this:

无论我在做什么,当我在表单中有两个按钮时,即使其中一个是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>

I know i should not be creating a form mid-table, but this is not the point. Please, tell me what am i doing wrong, as i have been fighting this problem for way too long.

我知道我不应该创建一个表格中间表,但这不是重点。请告诉我,我做错了什么,因为我一直在解决这个问题太久了。

1 个解决方案

#1


0  

As you can see here http://www.w3schools.com/tags/tag_button.asp you should define the type attribute of your button element in order to avoid unexpected behaviour

正如您在http://www.w3schools.com/tags/tag_button.asp中看到的那样,您应该定义按钮元素的type属性,以避免意外行为

So if you do not want to mess with javascript you can try this <button type="button" onclick="location.href='editStudent.cshtml?id=@row.No'">Edit record</button>

因此,如果你不想搞乱javascript你可以尝试这个

#1


0  

As you can see here http://www.w3schools.com/tags/tag_button.asp you should define the type attribute of your button element in order to avoid unexpected behaviour

正如您在http://www.w3schools.com/tags/tag_button.asp中看到的那样,您应该定义按钮元素的type属性,以避免意外行为

So if you do not want to mess with javascript you can try this <button type="button" onclick="location.href='editStudent.cshtml?id=@row.No'">Edit record</button>

因此,如果你不想搞乱javascript你可以尝试这个