System.Web.Mvc.HttpPostAttribute vs System.Web.Http.HttpPostAttribute? [duplicate]

System.Web.Mvc.HttpPostAttribute vs System.Web.Http.HttpPostAttribute? [duplicate]

回答1

Prior to ASP.NET Core, MVC and WebAPI were mainly separate libraries.

The .Mvc namespace applies to MVC controllers, the .Http namespace to Web API controllers.

 

What is the different between System.Web.Http.HttpPut Vs System.Web.Mvc.HttpPut

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

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.

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(); }

and [System.Web.Mvc.HttpPut] for MVC actions

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

 

 

作者:Chuck Lu    GitHub    
posted @   ChuckLu  阅读(110)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2020-10-21 codedom roslyn compilation error
2019-10-21 Check if List<Int32> values are consecutive
2019-10-21 comparison of truncate vs delete in mysql/sqlserver
2016-10-21 Group By
2016-10-21 The property 'RowId' is part of the object's key information and cannot be modified.
2016-10-21 HashCheck
2016-10-21 File Checksum Integrity Verifier
点击右上角即可分享
微信分享提示