April 2019 - Digital Tool Factory blog April 2019 - Digital Tool Factory blog

The Digital Tool Factory Blog

How to add extra parameters to post requests on asp.net web api 2

My only problem with asp.net web api 2 is the inability to pass additional parameters the action, along with a base object. For example – if you want to update a contact, but keep track of where the update request came from (the location is not really part of the contact object) you cannot just add location as an additional parameter in addition to contact.

The only way of doing this is to add a parameter to the route – for example

[System.Web.Http.Route(“Ajax/v1.1/{locationArea}/SomeContactAction”)]
[OutputCache(NoStore = true, Duration = 0)]
[System.Web.Http.HttpPostAttribute]
public bool IsUniqueEmail(string locationArea,Contact contact)
{
//stuff happens
DoStuff(contact, locationArea);
return bool;
}


12
Apr 19


Written By Steve French

 




Copyright 2011 Digital Tool Factory. All Rights Reserved. Powered by raw technical talent. And in this case, WordPress.