[FromBody] Model and Guid Display in Web Api 2
I am using web api 2 and I found strange Guid display behavior. Here is my definition of the problem
This is my example model
public class MyModel
{
public Guid Id { get; set; }
public string Name { get; set; }
}
I have the following actions on my controller where I have MyModel as input [FromBody]
[HttpPost, Route("create")]
public IHttpActionResult Create([FromBody]MyModel model)
{
// some implementation
}
Everything works fine, not Guid. When I post the JSON of the new MyModel to the request body:
{
"Id":"1d93dfa2-sb34-403d-a766-bdcf1cf47a71",
"Name":"name"
}
The name is set correctly as "name", but the Guid is generated as a new Guid each time.
What could be causing this problem? How do I set the correct display of the Guid value?
+3
source to share