×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: Phil Hack
Added: Sep 10, 2012 12:22 AM
Views: 67
Source: http://www.joe-stevens.com/2011/06/12/model-binding-mongodb-objectid-with-asp-net-mvc/
  1. Helper:
  2. public class ObjectIdBinder : IModelBinder
  3.     {
  4.         public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
  5.         {
  6.             var result = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);
  7.             return new ObjectId(result.AttemptedValue);
  8.         }
  9.     }
  10.  
  11. Global.asax.cs
  12. ModelBinders.Binders.Add(typeof(ObjectId), new ObjectIdBinder());