簡體   English   中英

如何在 MVC 中使用按鈕調用方法

[英]How to call a method with a button in MVC

我試圖簡單地從名為“ButtonController”的 controller 調用 void 類型方法,並在我的 index.cshtml 文件中有一個按鈕。 我試過了,但它沒有用:

<button type="button" onclick="location.href = '@Url.Action("Click", "ButtonController")'">Button</button>

了解如何使用 Url 中的引導按鈕。 使用 asp.net mvc5 操作

只是你可以使用兩種選擇之一。

<a href="@Url.Action("Index","Botton")">Go to button</a>
@Html.ActionLink("Go to botton", "Index", "Botton")

正如@chetan-ranpariya 所述,使用按鈕就像使用 Ajax

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM