我知道这是不对的,但为了说明问题,我想这样做:

<%= Html.Button("Action", "Controller") %>

我的目标是使一个HTML按钮,将调用我的MVC控制器的动作方法。


当前回答

我用的是Razor,但这两者都可以。我基本上是在链接中包装一个按钮。

<a href="Controller/ActionMethod">
    <input type="button" value="Click Me" />
</a>

其他回答

根据上面的几个答案,你可以这样做:

<button onclick="location.href='@Url.Action("ActionName", "ControllerName")'" />

最好用这个例子。

使用ActionLink调用动作和控制器:

@Html.ActionLink("Submit", "Action", "Controller", route, new { @class = "btn btn-block"})

Razor语法如下:

<input type="button" value="Create" onclick="location.href='@Url.Action("Create", "User")'" />

试试这个:

@Html.ActionLink("DisplayText", "Action", "Controller", route, attribute)

这应该对你有用。

<button type="button" onclick="location.href='@Url.Action("MyAction", "MyController")'" />

Type ="button"阻止页面提交,而是执行您的操作。