asp web api补丁实现 [英] asp web api patch implementation

查看:22
本文介绍了asp web api补丁实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有这个模型

public partial class Todo
{
    public int id { get; set; }
    public string content { get; set; }
    public bool done { get; set; }
}

我将此作为 json 数据作为补丁请求发送到我的控制器.这只是切换复选框的操作.我认为我只想将它发送到我的服务器而不是整个模型是有道理的.

And i send this as json data to my controller as a patch request. This is mearly the action of toggeling a checkbox. I think it makes sence that i only want to sent that to my server, and not the entire model.

{ "id":1, "done" : true }

我的 WebApi 控制器需要什么样子才能正确处理这个简单的 json 补丁请求?我应该为此使用 web api,还是应该在 mvc 中使用更具 rpc 风格的方法?

What does my WebApi controller need to look like in order to correctly process this, simple, json patch request ? Should i be using web api for this, or should i use a more rpc styled approach with mvc ?

这似乎是一件非常基本的事情,但我似乎做对了!我想我可能需要在我的控制器方法中使用不同的参数,但我不确定.

It seems like a very basic thing to do, but i can't seem to get it right ! I think i might need to use a different parameter in my controller method, but i'm not sure.

感谢您的宝贵时间.

推荐答案

您可以在 OData 预发布 Nuget 包中找到 PATCH 功能:Microsoft.AspNet.WebApi.OData.

You can find PATCH feature in the OData pre-release Nuget package: Microsoft.AspNet.WebApi.OData.

有关如何使用它来创建处理 PATCH 的操作的信息,请参见关于 ASP.NET Web API 中的 OData 支持.

Information how you can use it to create an action for handling PATCH can be found in the Partial Updates (PATCH requests) section of the blog post about OData support in ASP.NET Web API.

这篇关于asp web api补丁实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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