我在我的 ASP.NET MVC 4 项目中使用了 Restful Routing .NET NuGet 包 ( https://github.com/stevehodgkiss/restful-routing )。根据文档,我应该能够使用 PUT 动词通过将表单放入控制器中的更新操作来提交@HTML.PutOverrideTag()
表单。我无法让它发挥作用。每次提交表单时,我都会收到 404 Not Found 错误。谁能确认他们是否能够正常工作?我的代码如下:
路由配置.cs:
map.Resources<UsersController>();
意见\用户\edit.cshtml:
@using (Html.BeginForm("update", "users", new { id = Model.Id }))
{
@Html.PutOverrideTag()
<input id="user_submit" name="commit" type="submit" value="Update" />
}
用户控制器.cs:
[Authorize]
[HttpGet]
public ActionResult Edit(int id)
{
var user = UserRepository.GetById(id);
return View(user);
}
[Authorize]
[HttpPut]
public ActionResult Update(int id, User user)
{
return View("edit", user);
}
重建步骤:
- 浏览到:/user/edit
- 表格显示
- 按提交按钮
- 收到 404 Not Found 错误