asp网络API执行补丁 [英] asp web api patch implementation

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

问题描述

假设我有这个模型

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

我送这是JSON数据到我的控制器作为补丁请求。
这是mearly toggeling复选框的作用。
我认为它使SENCE,我只是想发送的到我的服务器,而不是整个模型。

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补丁的要求吗?我应该使用这个网页API,或者我应该用更RPC风格的方法与MVC?

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的pre-发布的NuGet包PATCH功能:<一href=\"https://nuget.org/packages/Microsoft.AspNet.WebApi.OData\">Microsoft.AspNet.WebApi.OData.

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

信息如何使用它来创建用于处理PATCH动作可以在部分更新(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网络API执行补丁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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