var resourcetoUpdate = new TestResourceModel() { ID = 5 name = "testname",Description = "description",etc... }
我希望客户端能够PUT到/ TestResource / 5来更新资源的属性
现在,假设客户端只想更新属性name,而不是更新描述,因此发送以下请求:
name="testNewname"
在这种情况下,资源应该更新,因此name现在是“testNewname”,put描述仍然是“描述”
我如何区分这种情况(在我的Controller方法中),以及客户端想要将Description属性设置为null的情况:
name="testNewname"Description=
因为我的控制器方法看起来像:
[httpPut]public ActionResult Index(TestResourceModel model){ //True in both cases bool descriptionSet = model.Description == null;解决方法 那么你必须将传入的值与你想要更新的值进行比较.我的意思是null是null是null 总结
以上是内存溢出为你收集整理的c# – 区分ASP.NET MVC4中的null和missing参数全部内容,希望文章能够帮你解决c# – 区分ASP.NET MVC4中的null和missing参数所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)