Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Make the ModelBinder support the JsonPropertyAttribute #7824

Closed
gregoryagu opened this issue May 24, 2018 · 2 comments
Closed

Make the ModelBinder support the JsonPropertyAttribute #7824

gregoryagu opened this issue May 24, 2018 · 2 comments
Assignees
Labels

Comments

@gregoryagu
Copy link

gregoryagu commented May 24, 2018

Is this a Bug or Feature request?:

Feature

Steps to reproduce (preferrably a link to a GitHub repo with a repro project):

Try to bind to "smtp-id" in a web api call. It cannot be done, as the dash is not allowed in a property name.

Description of the problem:

But there is no way to put an attribute on the Input Model to tell the ModelBinder to bind to "SmtpId"

public class InputModel{
[JsonProperty("smpt-id")]//It would be great if this would work.
public string SmtpId{get;set;}
}

I encountered this issue trying to process SendGrid event hooks. They use the dash and I cannot get them to change it.

Version of Microsoft.AspNetCore.Mvc or Microsoft.AspNetCore.App or Microsoft.AspNetCore.All: 2.02

@pranavkm
Copy link
Contributor

You should be able to annotate your property with [ModelBinder(Name = "smtp-id")] if you're dealing with model bound objects. That said, it looks like SendGrid uses Json payloads - https://sendgrid.com/docs/API_Reference/Event_Webhook/event.html#-Events - at which point, annotating it with JsonProperty would be right thing since the model would get deserialized by Json.NET

@mkArtakMSFT
Copy link
Member

Thanks for contacting us. We believe that the question you've raised have been answered. If you still feel a need to continue the discussion, feel free to reopen it and add your comments.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants