Custom ModelBinder for DateTime. Working, but is this ok?

Topics: Writing modules
Jun 6, 2011 at 10:42 PM
Edited Jun 6, 2011 at 10:44 PM

Hi there,
I have defined a custom ModelBinder for DateTime that I wish to use only when editing my custom part 'AioiProfile'.
Two questions:

  1. What is the correct way to register it? In pure mvc I would use Application_Start from Global.asax. I am now using IOrchardShellEvents.Activated. It is working. I am unsure though if this the correct/recommended approach.
  2. How do I limit it's scope? In pure MVC it can be achieved by placing the ModelBinder template in the appropiate View subfolder. In this case I want my ModelBinder to apply only for my part Editor. I have placed my DateTime.cshtml in Views/EditorTemplates Again, this works, but there is nothing preventing this ModelBinder from kicking in if another Form posts a field of type DateTime. Where should I place my binder template so that it applies only for my part? 

Thank you!

Jun 6, 2011 at 11:28 PM

I'm starting to realize that using a ModelBinder might not be the 'Orchard' way of achieving this.
I should create a custom field for this property instead. 
Any thoughts?