如何在 ASP.NET MVC 中添加按钮并从 C# 代码链接单击事件

Rad*_*adu 2 asp.net-mvc

我正在尝试在我的 ASP.NET 页面上添加一个按钮。我有使用 Windows 表单的经验,我知道如何将单击事件链接到按钮,但在 ASP.NET MVC 中,此链接是不同的。

如何正确制作此链接,以便在单击按钮时触发在我的 c# 源中编写的单击事件?

Hie*_*yen 5

您需要在 cshtml 文件中创建一个标签作为

<a class="btn btn-primary" href="@Url.Action("YourAction","YourController")">Click</a>
Run Code Online (Sandbox Code Playgroud)

并创建方法来处理控制器 c# 中的点击作为

public ActionResult YourAction()
{
    //C# code here
}
Run Code Online (Sandbox Code Playgroud)