Link to home
Create AccountLog in
.NET Programming

.NET Programming

--

Questions

--

Followers

Top Experts

Avatar of Dinesh Bali
Dinesh Bali

Post method is not accepting parameter in ASP.Net WEB API
Hi,

I have setup MVC web api application and was testing post method.
The parameter passed via postman is not captured in web api method.

[HttpPost]
        public IHttpActionResult Post([FromBody] string filterName)
        {
            return new JsonResult<string>(filterName, new JsonSerializerSettings(), Encoding.UTF8, this);
        }

Open in new window

What is wrong in passing the data.

Postman:
User generated image
Value in .Net while debugging:
User generated image
Full page code:
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Web.Http;
using System.Web.Http.Results;

namespace webapitestweb.Controllers
{
    public class ValuesController : ApiController
    {
        // GET api/values
        public IEnumerable<string> Get()
        {
            return new string[] { "value1", "value2" };
        }

        // GET api/values/5
        public string Get(int id)
        {
            return "value";
        }

        

        [HttpPost] 
        public IHttpActionResult Post([FromBody] string filterName) 
        {
            return new JsonResult<string>(filterName, new JsonSerializerSettings(), Encoding.UTF8, this);
        }

        // PUT api/values/5
        public void Put(int id, [FromBody] string value)
        {
        }

        // DELETE api/values/5
        public void Delete(int id)
        {
        }
    }
}


Open in new window


Please advise.

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


ASKER CERTIFIED SOLUTION
Avatar of it_saigeit_saige🇺🇸

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Avatar of Dinesh BaliDinesh Bali

ASKER

Many Thanks

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.

.NET Programming

.NET Programming

--

Questions

--

Followers

Top Experts

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.