【发布时间】:2017-05-27 21:52:10
【问题描述】:
我正在使用 asp.net core razor 引擎。有没有办法让锚标记像表单标记一样访问我的 Create 方法。我使用表单标签测试了我的代码,它可以工作,有没有办法让锚标签做同样的事情?
这是我的代码
<div id = "menu">
@model ecommerce.Models.Users
<a asp-controller="Product" asp-action="Create" method="post" role="form">Test</a> // This is the anchor tag that I want to have the same behavior as the form tag below
<form asp-controller="Product" asp-action="Create" method="post" role="form">
<button type="submit">Add to Quotes</button>
</form>
</div>
【问题讨论】:
-
为什么你想让锚标签像表单标签一样工作?为什么不使用表单标签助手本身?您的预期行为究竟是什么?
-
@Shyju,我想转到我的创建方法,而不是直接转到另一个页面
-
链接(锚标签)就是这样做的。你缺少什么?为什么你想让它表现得像一个表单?
-
@Aaron 在您的创建方法中,您可以重定向您想要的任何页面。这是服务器端的决定,与锚标记无关。
-
@nurdyguy,我遇到的问题是使用我的锚标签来访问我的创建方法。使用表格我没有问题。我将如何使用我的锚标记来做到这一点?
标签: html asp.net asp.net-mvc