public class CustomObjectModelBinder : IModelBinder { public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { HttpCookie c = controllerContext.HttpContext.Request.Cookies["foo"] CustomObject value = new CustomObject() { foo.Name = c.Values["Name"], foo.Rank = c.Values["Rank"] } return CustomObject }}
然后在 Application_Start()加上
ModelBinders.Binders.Add(typeof(CustomObject), new CustomObjectModelBinder());