MVC3 goes out of the box with JsonValueProviderFactory (), which is very convenient for binding incoming JSON to the model. Unfortunately, I cannot figure out how to set up model contracts with names that are different from incoming JSON. For example:
[DataContract(Name = "session")] public class FacebookSession { [DataMember(Name = "access_token")] public string AccessToken { get; set; } [DataMember(Name = "expires")] public int? Expires { get; set; } [DataMember(Name = "secret")] public string Secret { get; set; } [DataMember(Name = "session_key")] public string Sessionkey { get; set; } [DataMember(Name = "sig")] public string Signature { get; set; } [DataMember(Name = "uid")] public string UserId { get; set; } }
when passed in a json object representing a facebook session, the properties are secret and end accordingly, but the rest is not because the property name is different from the json key name. I would expect the datacontract serializer to try to bind the name specified in the attribute, but that doesn't seem to be the case. Does anyone have any workarounds?
Edit
An example of how I will use this model:
public ActionResult Log(int? custId, FacebookSession response) { ViewBag.Id = response.UserId; return View(); }
Matthew tschiegg
source share