HTML按钮调用的MVC控制器和操作方法 [英] HTML button calling an MVC Controller and Action method

查看:2747
本文介绍了HTML按钮调用的MVC控制器和操作方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是不对的,但为了说明的缘故,我想要做的是这样的:

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") %>'" />

这篇关于HTML按钮调用的MVC控制器和操作方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆