Quantcast
Channel: Web API
Viewing all articles
Browse latest Browse all 4850

parameter (body post) of my Asp.net Web API SignalR hub is always null

$
0
0

Hi , here is my server

public class MonitorController : SignalRBase<monitorHub>
    {
        [Route("api/Category")]
        [HttpPost]
        public async Task<IHttpActionResult> Post([FromBody] Category item)
        {
            if (item == null)
            {
                return BadRequest(); ;
            }

            // notify all connected clients
            Hub.Clients.All.Notfy(item);

            // return the item inside of a 201 response
            return Created(Request.RequestUri, item);
        }
}

Here is my model

 public class Category
    {
        public int categoryId { get; set; }
        public List<Product> products { get; set; }
    }
    public class Product
    {
        public Guid ProductID { get; set; }

        public double Price { get; set; }
        public int Qty { get; internal set; }
    }

Here is my  call

 public async Task<Uri> PostAsJsonAsync(Category item)
        {
            // Post the data to the server
            var serverUrl = "http://localhost:18648//api/Category";
            var _client = new HttpClient();
            HttpResponseMessage response = await _client.PostAsJsonAsync(serverUrl, item);
            response.EnsureSuccessStatusCode();

            // return URI of the created resource.
            return response.Headers.Location;
        }

But item is always null why?

item is paramter of api post method (body)

[Route("api/Category")]
        [HttpPost]
        public async Task<IHttpActionResult> Post([FromBody] Category item)
        {
            //  item is always null why?
            if (item == null)
            {
                // always pass here why ?
                return BadRequest(); ;
            }

whats wrong ?

my api is a signalr hub

Reagrds


Viewing all articles
Browse latest Browse all 4850

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>