Reputation: 1
I have a controller, model and view and I am trying to make an already existing @html.editoFor to a @html.dropdownfor so I can limit the user to select only three possible values (Open, Close, Onhold).
To be more specific, I want to change the input box created by an editorFor in my Create and Edit action of my controller to a selection box if possible.
If that isnt possible, then I was wondering how can I provide the model with three default values to accept so only those values can be submited to the DB...
Upvotes: 0
Views: 1134
Reputation: 3835
You can easily change the EditorFor, but unfortunately it's based on the type of the property, so if you have a string
in your model, and you change the EditorFor, you're changing it for all strings where you use EditorFor.
If you create a custom object, containing the value, and maybe the three possible values, it's easy to create a custom EditorFor for this.
Take a look here: http://buildstarted.com/2010/09/10/overriding-displayfor-and-editorfor-to-create-custom-outputs-for-mvc/
(This is for version 3, but I haven't read anywhere that it has been changed for version 4, so give it a go)
Upvotes: 1