>Depending on how you send the data on the client:
>
>* Using jQuery or any other wrapper library it'll automatically encode form variables and URL parameters
>* Even if you hardcode the query string parameters on the URL the browser will automatically encode them
>
>Using a dictionary in this situation just makes the API a bit convoluted because it's not clear what the API expects for parameters exactly. If you're using GET, you can just map query string parameters directly to parameter names (ie. &id=xxxx) maps to Get(string id) or [Route(person/{id}] and person/xxxx. You don't even need [FromUri]. Your approach works but it's much less expressive for the person consuming the API.
>
>+++ Rick ---
We're using angularJs (1.6.04) and ASP.NET.MVC. The value was passed as is, e.g. I was seeing in the url:
1/sometext
When this text contained / I had problems. The angular.js service implementation was as following:
/**
* @public
* @param {int} attributeId
* @param {string} criteria
* @returns {ng.IPromise}
*/
MatrixTemplatesService.prototype.getAttributeValues = function (attributeId, criteria) {
var deferred = services.Deferred;
let keyValuePair = { Key: attributeId, Value: criteria };
services.Http.get("api/matrixTemplates/getAttributeValues",
{ params: keyValuePair }
)
.then(function (data) {
deferred.resolve(data.data);
});
return deferred.promise;
};
So, how I was supposed to code this line (criteria is a plain text at that point)
services.Http.get("api/matrixTemplates/getAttributeValues/" + id + "/" + criteria);
and the receiving line in my API?
Thanks a lot in advance.
If it's not broken, fix it until it is.
My Blog