Greetings I have a WCF service, and basically what the API users do to create a book is following:
var Book = new DtoBook()
{
OpenInModal = false,
CallToActionUrl = "url"
Status = NotificationStatus.Unseen,
TimeStamp = DateTime.Now,
Type = NotificationType.Type,
Message = "test,
};
BookManager.Instance.Add(Book);
I have users to basically do the same thing but instead on the client-side.
I have created a POST method already that looks like this:
public HttpResponseMessage Add(List<DtoBook> Books)
{
if (!ModelState.IsValid)
{
return Request.CreateResponse(HttpStatusCode.BadRequest);
}
BookManager.Instance.Add(Books);
var response = Request.CreateResponse(HttpStatusCode.Created, Books);
return response;
}
So when I enter the url I get following in my console:
{"Message":"The request is invalid.","MessageDetail":"The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.String Get(Int32)' in 'test.Controllers.NotificationsController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter."}
My question is what do I need to do so the user can type the properties of the dToBook class and then the POST happens and the book gets added. I guess right now it just tries to add it without any properties.
Any kind of help is appreciated
Try to specify the method is post, for sample:
[HttpPost]
public HttpResponseMessage Add([FromBody]List<DtoBook> Books)
{
// code
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.