Asp.NET MVC中的HttpPatch请求
我正在尝试在带有HttpPatch注释的控制器中使用方法。我的问题是,当我触发该方法时,我有404错误,找不到资源。当我按下“补丁”按钮而不是HttpPatch请求时,似乎无法满足方法需求并发送HttpPost请求。如果有人知道如何使用HttpPatch注释触发我的补丁方法。这是我的控制器:Asp.NET MVC中的HttpPatch请求,asp.net,asp.net-mvc,httprequest,http-patch,Asp.net,Asp.net Mvc,Httprequest,Http Patch,我正在尝试在带有HttpPatch注释的控制器中使用方法。我的问题是,当我触发该方法时,我有404错误,找不到资源。当我按下“补丁”按钮而不是HttpPatch请求时,似乎无法满足方法需求并发送HttpPost请求。如果有人知道如何使用HttpPatch注释触发我的补丁方法。这是我的控制器: [HttpPatch] public ActionResult Patch() { return View(); } [HttpPatch] public ActionResult Proce
[HttpPatch]
public ActionResult Patch()
{
return View();
}
[HttpPatch]
public ActionResult ProcessLogin()
{
//some code ...
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" />
}
以下是使用Ajax解决我的问题的方法:
@model Practice.Models.Account.RegistrationViewModel
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Login</title>
<script src="~/scripts/jquery-2.2.1.min.js"></script>
<script src="~/scripts/jquery.unobtrusive-ajax.min.js"></script>
</head>
<body>
<div>
@using (Ajax.BeginForm("ProcessLogin", "Account", new AjaxOptions() { HttpMethod = "PATCH" }))
{
@Html.LabelFor(x => x.Login)
@Html.EditorFor(x => x.Login)
<br />
@Html.LabelFor(x => x.Password)
@Html.PasswordFor(x => x.Password)
<input type="submit" value="Login" />
}
</div>
</body>
</html>
您需要通过javascript@Jasen发出补丁请求谢谢您的回答。所以,我必须使用javascript生成请求头?使用方法生成AJAX请求PATCH@Jasen谢谢,它很管用!
[HttpPatch]
public ActionResult ProcessLogin()
{
//some code ...
return View();
}