System.Web.Http.HttpPut和System.Web.Mvc.HttpPut有什么区别 [英] What is the different between System.Web.Http.HttpPut Vs System.Web.Mvc.HttpPut

查看:229
本文介绍了System.Web.Http.HttpPut和System.Web.Mvc.HttpPut有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

System.Web.Http.HttpPut System.Web.Mvc.HttpPut 有什么区别?

在Web API项目上使用[HttpPut]会导致错误405-请求的资源不支持http方法"PUT".

Using [HttpPut] on the Web API project results the error 405 - The requested resource does not support http method 'PUT'.

推荐答案

它们属于两个不同的框架.每个人的管道流程都在寻找属于其各自名称空间的特定属性.

They belong to two different frameworks. The pipeline flow of each is looking for specific attributes that belong to their respective namespaces.

各个框架的路由引擎都不知道另一个,因此,如果在MVC操作上使用Web API属性,就好像根本没有属性一样,因此会遇到405错误.

The routing engine for the respective frameworks are not aware of the other so if a Web API attribute is used on a MVC action it would be just as if there were no attribute at all, hence the 405 error encountered.

确保在正确的控制器类型上使用了正确的名称空间.如果文件中同时使用了两个名称空间,则可以通过调用[System.Web.Http.HttpPut]进行Web API操作

Make sure that the correct namespace is used on the correct controller type. If both namespaces are being used in the file then be specific by calling [System.Web.Http.HttpPut] for Web API actions

[System.Web.Http.HttpPut]
public IHttpActionResult Put([FromBody]MyModel model) { return Ok(); }

[System.Web.Mvc.HttpPut]用于MVC操作

[System.Web.Mvc.HttpPut]
public ActionResult Put([FromBody]MyModel model) { return View(); }

这篇关于System.Web.Http.HttpPut和System.Web.Mvc.HttpPut有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆