Anybody know how to easily reuse the built in model binders in .Net Core?
I have to make a call to an api regularly that returns with NamedValuePaired data (like a querystring) Is there an easy way to just take reuse the model binder instead of parsing the data?
I could just take the data and make another call to a controller of my own to do the binding but, there has to be way other than doing a http post to my own controller.
Currently I am doing the following:
var rawResponse = "";
using (var client = new HttpClient())
{
//Post to paypal
var response = await client.PostAsync(_options.TokenUrl, new StringContent(parameters, Encoding.UTF8, "text/namevalue"));
//read response
rawResponse = await response.Content.ReadAsStringAsync();
}
var nameValues = QueryHelpers.ParseQuery(rawResponse);
Model m = new Model();
if (nameValues.ContainsKey("RESULT"))
m.Result = Convert.ToByte(nameValues["RESULT"].FirstOrDefault());
// etc....
Ideally I'd like to take the response and pass it through a the built in model binder like it was being posted to me.