使用 ASP.NET MVC 中的按钮处理页面操作的正确方法?
我正在使用 ASP.NET MVC 编写一个应用程序,由于各种原因,导航是通过 HTML 输入按钮处理的。 如何处理这种情况的最佳实践是什么?
在需要发布信息的按钮上设置一个表单,并在不需要保留信息的按钮上使用 JavaScript 进行重定向
通过表单处理所有按钮,以达到迷你表单处理不需要保留信息的按钮上的导航的程度被保留
<% 使用 (Html.BeginForm()) {%> <输入类型=“隐藏”名称=“控制器”值=“1”/> <输入类型=“隐藏”名称=“操作”值=“位置”/> <% } %>
我在这里没有想到的事情< /p>
I'm writing an app with ASP.NET MVC where, for various reasons, the navigation is handled through HTML input buttons. What are the Best practices on how to handle this situation?
Set up a Form on the buttons where information needs to be POSTed and just use JavaScript to redirect on the buttons where information doesn't need to be retained
Have all buttons handled through forms, to the point where a mini-form handles navigation on the buttons where the information doesn't need to be retained
<% using (Html.BeginForm()) { %> <input type="hidden" name="controller" value="1" /> <input type="hidden" name="action" value="Location" /> <input id="BackButton" type="submit" value="Go Back" /> <% } %>
Something I haven't thought of here
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用空的
标签和 Javascript/jQuery。 例如:
在视图中:
navigation.js 中的某处:
Use empty
<a href="#">
tags and Javascript/jQuery. For example:In View:
Somewhere in navigation.js:
3:将一些锚标记设置为看起来像按钮。
在最近的一个应用程序中,我们实现了选项 1。客户喜欢在所有表单上都有“取消”按钮(...),因此我们只是在重置输入上添加了一个单击事件,该事件执行以下操作:
3: Style some anchor tags to look like buttons.
On a recent application we implemented option 1. The client liked having "Cancel" buttons on all the forms (...) so we just stuck a click event on the reset inputs which did:
使用迷你表格看起来确实很重。 您基本上希望使用按钮作为链接(我会认真考虑为什么您打破了非常基本的网络约定:按钮发布/修改和链接导航),因此越基本,您就可以做得越好。
Using a mini form seems really heavy handed. You are basically looking to use a button as a link (I'd look seriously at why you are breaking that very basic web convention: buttons post/modify and links navigate) so the more basic you can make it the better.
在这里您可以找到一篇关于如何设置锚标记样式的非常好的文章像一个按钮
Here you can find a pretty good article on how to style an anchor tag like a button