I have multiple controller actions that takes an id
public ActionResult Get(int? id) { ... } public ActionResult Delete(int id) { ... } public JsonResult GetJson(int? id) { ... }
I’m thinking its best practice to use a ModelBinder (SomeObjectFromIDModelBinder) on each action, so the obtaining of the object is separated from the controller, and keeps the action methods smaller.
The reason I don’t want it to be called SomeObjectModelBinder is because I also have a need to recreate Models from JSON, so have a SomeObjectFromJsonModelBinder which handles recreating the ‘SomeObject’ from a JSON string.
I’m thinking this is a suitable usage of ModelBinders (naming convention), but just wanted clarification. Thoughts?
I’ve decided that it is acceptable to do what I was asking, and having multiple ModelBinders that will bind different data to a Model.