c# - Modify Parameter Binding in ASP.NET Web API via Attribute Usage -


my goal have controller method

i trying create attribute defaultvalue below:

class modelclass {   int modelid;    string modelname;    [defaultvalue("foo")]   string modelstring; }  class modelclass2 {   string foobar;    [defaultvalue("bar")]   string otherstringvalue; } 

with controller:

[httpput] public async task<httpresponsemessage> put(modelclass model) { ... }  [httppost] public async task<httpresponsemessage> put(modelclass2 model2) { ... } 

the way defaultvalue work when user passes value in, if modelstring in modelclass null or empty string, populate "foo" (from constructor of attribute). else, user defined value used. same true of otherstringvalue in modelclass2

in asp.net mvc looks can accomplished using bindproperty method of imodelbinder interface, can't find similar webapi


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -