我正在使用带有 MVC5 的新属性路由,并通过将and属性添加到我的操作方法中来获得 httpGET
和方法约束。但是当我添加时,我只会得到一个 404 错误页面。有谁知道我需要做什么才能使属性路由与 http 一起使用?请参见下面的代码:POST
[HttpGet]
[HttpPost]
[HttpPut]
PUT
[HttpGet]
[Route("edit")]
public ActionResult Edit() {
// this works
return View();
}
[HttpPost]
[Route("insert")]
public ActionResult Insert() {
// this works
return View();
}
[HttpPut]
[Route("update")]
public ActionResult Update() {
// this does not work
return View();
}
我试过了X-HTTP-Method-Override=PUT
POST /update HTTP/1.1
Host: localhost:61794
Content-Length: 32
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36
Content-Type: application/x-www-form-urlencoded
X-HTTP-Method-Override=PUT&text=
而且还带有真实的PUT
PUT /update HTTP/1.1
Host: localhost:61794
Content-Length: 5
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36
Content-Type: application/x-www-form-urlencoded
text=