调用 MVC 控制器和操作方法的 HTML 按钮 [英] HTML button calling an MVC Controller and Action method
本文介绍了调用 MVC 控制器和操作方法的 HTML 按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道这是不对的,但为了说明起见,我想做这样的事情:
I know this isn't right, but for the sake of illustration I'd like to do something like this:
<%= Html.Button("Action", "Controller") %>
我的目标是制作一个 HTML 按钮来调用我的 MVC 控制器的操作方法.
My goal is to make an HTML button that will call my MVC controller's action method.
推荐答案
根本不需要使用表单,除非您想发布到操作.输入按钮(不是提交)可以解决问题.
No need to use a form at all unless you want to post to the action. An input button (not submit) will do the trick.
<input type="button"
value="Go Somewhere Else"
onclick="location.href='<%: Url.Action("Action", "Controller") %>'" />
这篇关于调用 MVC 控制器和操作方法的 HTML 按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文