I need to bind the value in html select option and I have the values in a C# model. How do I do this? My html code:
<div class="Div"><span class="label2">values:</span>
<select id="Binding_values" onchange="values()></select></div>
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Assuming you have a view model:
and a controller action which will populate this view model and pass it to the view:
inside the corresponding strongly typed view you could use the
DropDownListForhelper:and if this dropdown is inside an HTML for posting back to the controller you could have an action that will retrieve the selected value from the model:
Assuming you want to send the selected value to the server immediately after changing the selection in the dropdown without clicking on a form submit button you could give this DropDownList an unique id:
and then subscribe to the
.change()event of this dropdown using jQuery and submit the containing form: