weixin_33724046 2018-05-25 14:15 采纳率: 0%
浏览 94

MVC Http PUT不起作用

when using HTTP post to update my times record for example it works, but when i use put it doesn't. I have read some articles about CRUD and HTTP methods, and as known HTTP PUT is for the update part, is it only for WEB API or can i use it in my .net mvc project and im doing something wrong? Here's my code

var times = GetTimes(); // times array object

var enrollmentId = $('#EnrolledSubject').data('id');

$.ajax({
    contentType: 'application/json; charset=utf-8',
    url: "/Subjects/UpdateTimes?enrollmentId="+enrollmentId,
    type: "PUT",
    dataType: "json",
    data: JSON.stringify({ 'times': times}),
    success: function (data) {
        console.log(data);
    },
    error: function (x, y, z) {
        console.log('error ' + y);

        OnAJAXError(x, y, z);
    }
});

and MVC controller Subjects

[Route("UpdateTimes")]
[HttpPut]
public bool UpdateTimes(List<Time> times)
{
     return true;
}
  • 写回答

2条回答 默认 最新

  • weixin_33694620 2018-05-25 14:47
    关注

    The issue might be coming from your iis configuration. You could try adding this in your web.config :

    <system.webServer>
        <handlers>
            <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
            <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
        </handlers>
    </system.webServer>
    
    评论

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行