ASP.NET MVC Ajax.ActionLink用POST传入参数时找不到执行方法
前端代码:
<script scr="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
<div id="server-time"></div>
<p>
@Ajax.ActionLink("Get time","Time","Time",new { productId = 2 }, new AjaxOptions
{
UpdateTargetId = "server-time",
InsertionMode = InsertionMode.Replace,
HttpMethod="Post"
}
)
</p>
后端代码:
public class TimeController : Controller
{
// GET: Time
[HttpPost]
public ActionResult Time(int productId, int amount=1)
{
var time = DateTime.Now.ToString("yyyy/M/d HH:mm:ss") + "productId:" + productId + ",amount:" + amount;
return Content(time);
}
public ActionResult Index()
{
return View();
}
}
“/”应用程序中的服务器错误。
无法找到资源。
说明: HTTP 404。您正在查找的资源(或者它的一个依赖项)可能已被移除,或其名称已更改,或暂时不可用。请检查以下 URL 并确保其拼写正确。
请求的 URL: /Time/Time