MVC 3 model binding with underscores

Viewed 2150

I'm posting json with variables names with underscores (like_this) and attempting to bind to a model that is camelcased (LikeThis), but the values are unable to be bound.

I know I could write a custom model binder, but since the underscored convention is so common I'd expect that a solution already existed.

The action/model I'm trying to post to is:

/* in controller */
[HttpPost]
public ActionResult UpdateArgLevel(UserArgLevelModel model) {
    // do something with the data
}

/* model */
public class UserArgLevelModel {
    public int Id { get; set; }
    public string FirstName { get; set; }
    public string Surname { get; set; }
    public int ArgLevelId { get; set; }
}

and the json data is like:

{
    id: 420007,
    first_name: "Marc",
    surname: "Priddes",
    arg_level_id: 4
}

(Unfortunately I can't change either the naming of either the json or the model)

1 Answers
Related