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

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

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


当前回答

最好用这个例子

<a href=“@Url.Action(”Register“,”Account“, new {id=Item.id })” class=“btn btn-primary btn-lg”>Register</a>

其他回答

如果你在主页(“/ home /Index”),你想调用管理控制器的索引动作,下面将为你工作。

<li><a href="/Admin/Index">Admin</a></li>

试试这个:

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

这应该对你有用。

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

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

Razor语法如下:

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

举个例子:

<button name="nameButton" id="idButton" title="your title" class="btn btn-secondary" onclick="location.href='@Url.Action( "Index","Controller" new {  id = Item.id })';return false;">valueButton</button>