I have to bind an Html.DropDownList
with just two items statically.
Text="Yes" Value="1"
Text="No" Value="0"
The important thing is that, I have to set the text and value fields.
How can I do this?
I have to bind an Html.DropDownList
with just two items statically.
Text="Yes" Value="1"
Text="No" Value="0"
The important thing is that, I have to set the text and value fields.
How can I do this?
It is a best practice not to create the SelectList in the view. You should create it in the controller and pass it using the ViewData.
Example:
you pass to the constratctor: the IEnumerable objec,the value field the text field and the selected value.
in the View:
I used this is properly working
This solved it for me:
Code below assumes you are using razor view engine if not you will need to convert it.
You should consider creating the model in your code instead of the view. Also this would be a good candidate for an editor template.
if you want to be alittle explicity then try