There is a Web API application.

There is an Action that catches the request:

[HttpPost] public HttpResponseMessage GetOrder(OrderRequest request) { return ResponseHandler.GetResponse(Request, ActionHandler.Order(request)); } 

There is a Model with the description of the query properties:

 public class OrderRequest { public int OrderId { get; set; } public string Description { get; set; } } 

In the client that sends a POST request, the Description parameter is passed as $Description , respectively, when the request hits the Action only the OrderId field is OrderId , and the Description parameter is left blank.

How in the OrderRequest for the Description property to indicate that it should be mapped on $Description in the request?

Can this be made an attribute of the Description property?

And if you can throw an article with the theory of how such a mapping is done, I did not find

1 answer 1

Can so

 public class OrderRequest { public int OrderId { get; set; } [JsonProperty("$Description")] public string Description { get; set; } } 

UPDATE:

Controller:

 //Controllers/OrdersController.cs using System.Web.Http; using WebApplication1.Models; namespace WebApplication1.Controllers { public class OrdersController : ApiController { [HttpPost] public string GetOrder(OrderRequest request) { return string.Format("OrderRequest(OrderId='{0}', Description='{1}')", request.OrderId, request.Description); } } } 

Model:

 //Models/OrderRequest.cs using Newtonsoft.Json; namespace WebApplication1.Models { public class OrderRequest { public int OrderId { get; set; } [JsonProperty("$Description")] public string Description { get; set; } } } 

Check on Postman e:

Postman Check

  • does not work .... - tCode
  • checked on asp.net 4.6.1 - works, then the project translated to 4.5 also works - Ali
  • added more detailed information - Ali
  • Checked by Postman himself. If you send as JSON, then everything is really ok, but in the current client implementation it becomes clear that the request is not sent to JSON, is sent by a regular post from the form x-www-form-urlencoded - in this case, your option does not work - tCode