我知道这是不对的,但为了说明问题,我想这样做:
<%= Html.Button("Action", "Controller") %>
我的目标是使一个HTML按钮,将调用我的MVC控制器的动作方法。
我知道这是不对的,但为了说明问题,我想这样做:
<%= Html.Button("Action", "Controller") %>
我的目标是使一个HTML按钮,将调用我的MVC控制器的动作方法。
当前回答
好的,你基本上需要将动作传递给按钮,并在点击发生时调用它,它不需要在from中,你可以使用HTML onclick on button在按钮被点击时触发它…
<button id="my-button" onclick="location.href='@Url.Action("YourActionName", "YourControllerName")'">Submit</button>
其他回答
试试这个:
@Html.ActionLink("DisplayText", "Action", "Controller", route, attribute)
这应该对你有用。
<button type="button" onclick="location.href='@Url.Action("MyAction", "MyController")'" />
Type ="button"阻止页面提交,而是执行您的操作。
如果你在主页(“/ home /Index”),你想调用管理控制器的索引动作,下面将为你工作。
<li><a href="/Admin/Index">Admin</a></li>
根据上面的几个答案,你可以这样做:
<button onclick="location.href='@Url.Action("ActionName", "ControllerName")'" />
好的,你基本上需要将动作传递给按钮,并在点击发生时调用它,它不需要在from中,你可以使用HTML onclick on button在按钮被点击时触发它…
<button id="my-button" onclick="location.href='@Url.Action("YourActionName", "YourControllerName")'">Submit</button>