Using abstract classes as controller parameters in ASP.NET MVC4

As a part of the API for our prod­uct, we have the need to allow the UI to send us a par­cel of data, and we need to process it dif­fer­ent­ly based sole­ly on a sin­gle para­me­ter in the data.  We have decid­ed to cre­ate an abstract mod­el class to han­dle this, but MVC’s DefaultModelBinder does­n’t work out of the box on abstract class­es (or inter­faces).  There are many dis­cus­sions out there on this, and the accept­ed way to solve this prob­lem is to cre­ate a new ModelBinder class that has more knowl­edge of the inter­nals of your appli­ca­tion than the default does.  I thought about this some, and I decid­ed to try out a few tweaks to the process.

Continue read­ing “Using abstract class­es as con­troller para­me­ters in ASP.NET MVC4

Accepting multiple parameters the “RESTful” way using ASP .NET Web API

I came upon a require­ment at work to sup­port accept­ing mul­ti­ple ids in the Url of a “REST” request. I have no idea if this is actu­al­ly con­sid­ered RESTful or not, but the task was to for­mu­late the URL like so:

GET /FooResource/id1;id2;id3;id4/

The inten­tion was to be able to retrieve mul­ti­ple instances of FooResource with one request.

So, I came up with the fol­low­ing MVC ActionFilter to make my life a lit­tle bit easier:

Continue read­ing “Accepting mul­ti­ple para­me­ters the “RESTful” way using ASP .NET Web API