asp.net - ModelBindingContext.ValueProvider.GetValue returning nothing even though there is a key for the value I am retrieving -


i working on asp.net mvc3 project.

i have implemented custom imodelbinder class.in bindmodel method attempting retrieve id (a guid) of item this:

public class myviewmodelmodelbinder     implements imodelbinder      public function bindmodel(controllercontext system.web.mvc.controllercontext, bindingcontext system.web.mvc.modelbindingcontext) object implements system.web.mvc.imodelbinder.bindmodel           dim myvm myviewmodel          if (bindingcontext.model isnot nothing andalso typeof bindingcontext.model myviewmodel)             myvm = directcast(bindingcontext.model, myviewmodel)          else             myvm = new myviewmodel          end if            dim proposedobjectid guid = getvalue(of guid)(bindingcontext, "objectid")          myvm.objectid = proposedobjectid          '...'          return myvm     end function     private function getvalue(of t)(byval bindingcontext modelbindingcontext, byval key string) t         dim returnvalue t = nothing         dim valueresult valueproviderresult         valueresult = bindingcontext.valueprovider.getvalue(key)         if valueresult isnot nothing             try                 returnvalue = directcast(valueresult.convertto(gettype(t)), t)             catch ex exception                 returnvalue = nothing             end try         end if         return returnvalue     end function end class 

the problem having in getvalue method because bindingcontext.valueprovider.getvalue(key) method returning null/nothing. 1 assume because key and/or value isn't in valueprovider not case...the modelbindingcontext.valueprovider.getvalue returning null/nothing though there key , value item trying retrieve.

i can retrieve id doing following:

 public function bindmodel(controllercontext system.web.mvc.controllercontext, bindingcontext system.web.mvc.modelbindingcontext) object implements system.web.mvc.imodelbinder.bindmodel          dim proposedobjectid guid           guid.tryparse(ctype(bindingcontext.valueprovider, formcollection)("objectid"), proposedobjectid)         '...'  end function 

but having hard time understanding why getvalue method isn't retrieving value properly.

could please explain i'm doing wrong?

thank you.

i found problem!

i had accidentally added space end of key providing getvalue method. so, key (with appended space) didn't exist in collection!


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -