按下按钮时ASP.NET核心禁用验证
在剃须刀页面上,我有两个类型的“提交”按钮。
第一个按钮用于将数据添加到本地表,第二个按钮用于添加数据库中的所有列。
我想防止第一个按钮检查字段的验证,只有第二个按钮检查字段。
如何防止第一个按钮检查字段的验证?
(ASP.NET核心)
On the razor page, I have two buttons of type 'submit'.
The first button is used to add data to a local table, and the second button is used to add all columns in the database.
I want to prevent the first button from checking the validation of fields, only the second button checks the fields.
How to prevent the first button from checking the validation of the fields?
(ASP.NET Core)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将
formnovalidate
添加到第一个按钮输入。FormNovalidate
属性可以跳过客户端的验证,但无法跳过服务器端的验证。因此,您可以清除模型状态以跳过服务器端的验证。以下是MVC演示,您可以参考它。
Custom.cs:
in HomeController.cs:
view:
result:
Add
formnovalidate
to the first button input. Andformnovalidate
attribute could skip the validation in client side,but could not skip validation in server side. So you could clear model state to skip validation in server side.Below is a mvc demo, you can refer to it.
Custom.cs:
In HomeController.cs:
View:
Result:
我相信有很多方法可以处理此操作...
您可以直接使用带有不同按钮的不同控制器,其中一个可以像在此链接中一样,您可以使用不同的方式。我希望这会有所帮助。
disable验证链接
I am sure there are many ways to handle this...
You can direct to different controllers with different buttons and one of them would be like in this link and there are differents ways in it that you can use.. Check this out. I hope this helps.
Disable Validation Link
您可以创建以下两个按钮。
当
type =“ submit”
按钮触发时,将发送帖子请求。在另一种情况下,可以执行Get请求,您可以在GET相关操作方法中编写代码。You can create those two buttons like below.
The post request will be sent when the
type="submit"
button is triggered. In the other case, the get request can be executed and you can write your code inside the get related action method.