我正在使用HttpPatch部分更新對象。爲了得到這個工作,我使用了OData的Delta和Patch方法(在這裏提到:What's the currently recommended way of performing partial updates with Web API?)。似乎一切正常,但注意到映射器是區分大小寫的;當以下對象傳遞的屬性得到更新值:asp.net mvc web api部分更新OData修補程序
{
"Title" : "New title goes here",
"ShortDescription" : "New text goes here"
}
但是當我通過與較低或駝峯性質相同的對象,補丁不起作用 - 新價值是不會通過,所以看起來像反序列化和屬性映射有問題,即:「shortDescription」到「ShortDescription」。
是否有一個配置節會忽略大小寫使用補丁?
FYI:
在輸出時我有使用以下格式駝峯特性(以下REST最佳實踐):
//formatting
JsonSerializerSettings jss = new JsonSerializerSettings();
jss.ContractResolver = new CamelCasePropertyNamesContractResolver();
config.Formatters.JsonFormatter.SerializerSettings = jss;
//sample output
{
"title" : "First",
"shortDescription" : "First post!"
}
我的模型類不過是follwing C#/。NET格式約定:
public class Entry {
public string Title { get; set;}
public string ShortDescription { get; set;}
//rest of the code omitted
}
嗨裏克,謝謝你的回答, 我加入的代碼,但也有一些差異(使用MVC 5現在),它不工作: ' VAR道具= p in this.GetType()。GetProperties() let attr = p.GetCustomAttributes(typeof(NotPatchableAttribute),false) where attr == null select p; ' 但是,該查詢不會返回任何內容。 – 303
@ 303 Oh ..我正在使用web api 2,讓我快速在mvc 5上測試它,然後我會回覆你..沒有東西是不可溶解的:) –
@ 303我剛剛在一個新的mvc項目中測試它,似乎工作。爲了速度的緣故,我只是修改了編輯方法來使用補丁,並且它工作正常。我會把代碼放在github上供你比較。 –