Samantha J T Star
Samantha J T Star

Reputation: 32828

Is there a way to make an ASP.NET POST method work without a model as a param?

Here's my method now:

    public class UserTestAdminTestId
    {
        public int AdminTestId { get; set; }
    }

    [HttpPost]
    [Route("Post")]
    public async Task<IHttpActionResult> Post([FromBody]UserTestAdminTestId userTestAdminTestId)

There's more code inside of the Post Method and the only data I need for it is the AdminTestId.

I made a model (class) to accept this but assuming that I send the AdminTestId as a JSON object, is there a way for me to tell the post method what to expect without creating a class for just one object?

Upvotes: 0

Views: 37

Answers (1)

Jeroen Vannevel
Jeroen Vannevel

Reputation: 44448

Yes, but it will have to be a nullable int.

Keep in mind though that your body is only bound to one variable so if you have multiple values, you'll have to group them in a single type.

Upvotes: 1

Related Questions