![](/img/trans.png)
[英]jquery $post 405 (Method Not Allowed) to ASP.NET Folder
[英]how to send array of object to server. Asp.Net Core 3.1 405 Method Not Allowed
我正在尝试将 object 数组发送到 web Api 后 ActionResult 方法。 我的对象数组看起来像这样
'[{"TitleFeature":"عنوان یک","ValueFeature":"مقداریک","IdProduct":"1"},{"TitleFeature":"عنوان یک","ValueFeature":"مقداریک","IdProduct":"1"}]'
我的 function JS 看起来像这样
const uri = '/api/Feature/PostFeatures';
const baseURL = window.location.origin;
var dataFeature = getFeature();
var features = JSON.stringify(dataFeature);
$.ajax({
contentType: "application/json",
dataType: 'json',
type: "POST",
url: (baseURL + uri),
data: features,
});
我的 Controller.cs 看起来像这样
[HttpPost]
[AllowAnonymous]
public async Task<ActionResult<Feature>> PostFeatures([FromBody] List<Feature> features)
{
if (features != null)
foreach (var item in features)
{
_context.features.Add(item);
}
await _context.SaveChangesAsync();
return Ok();
}
我使用基于角色的授权,这是我的角色:
[Route("api/[controller]")]
[ApiController]
[Authorize(Roles = "admin")]
public class FeatureController : ControllerBase
如何修复错误 405?
405
错误表示你输入了URL但是http请求不匹配,所以如果你的action方法没有路由属性,可以尝试将Z2705A83A5A0656/FeatureEDED345Z请求的地址改为.../api/Feature
27
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.