在ASP MVC Web API中,如果我有这样的模型类:
class UpdateModel
{
public string name { get; set; }
public Date date { get; set; }
public string type { get; set; }
}
和这样的方法:
public object Update(UpdateModel m)
{
// update the object in the database according to the passed model
}
如果用户发布了一个JSON对象,如{" type":" banana" }并省略名称,如何判断用户是否正在尝试更新类型,但他们根本不想更新名称?如果他们通过{" name":null,"输入":" banana"这表明他们想要更新名称,他们希望它为null,因为在Update()方法中,模型看起来是一样的。