Reputation: 26919
In TypeScript
I have something like this:
$.post(this.serviceUrl + '/GetMyCodes', JSON.stringify(item.MyCodeList.trim()), function (CodeData: Something.SomethingElse) {
and my POST method is something like this:
[HttpPost]
public JsonResult GetMyCodes([JsonBody] string myCode)
My problem is how can I need to pass one more value to this service. How can I do that?
Upvotes: 0
Views: 257
Reputation: 16801
You could create a model which holds all values you want to post
public class postModel
{
public string myCode { get; set; }
public string myDescription { get; set; }
}
Define the controller to read the model from the body
[HttpPost]
public JsonResult GetMyCodes([FromBody] postModel model)
Then create an object in your client that matches the model structure
var obj = { myCode: 'myCode', myDescription: 'myDescription' };
$.post(this.serviceUrl + '/GetMyCodes', JSON.stringify(obj);
Upvotes: 1