我正在尝试在带有 HttpPatch 注释的控制器中使用方法。我的问题是,当我触发该方法时,出现 404 错误,找不到资源。当我按下“Patch”按钮而不是 HttpPatch 请求时,我似乎不满足方法需求并发送 HttpPost 请求。如果有人知道如何使用 HttpPatch 注释触发我的 Patch 方法。这是我的控制器:
[HttpPatch]
public ActionResult Patch()
{
return View();
}
这是我的看法:
@model Practice.Models.PatchModel
<h2>Index</h2>
@using (Html.BeginForm("Patch", "Home"))
{
<div>
@Html.Label("Age")
<div>
@Html.TextBoxFor(model => model.age)
</div>
</div>
<div>
@Html.Label("ID")
<div>
@Html.TextBoxFor(model => model.id)
</div>
</div>
<input type="submit" value="Patch" />
}
这是我的模型:
namespace Practice.Models
{
public class PatchModel
{
public int age { get; set; }
public int id { get; set; }
}
}