0

I was trying to get a text from the DropdownList like that :

$('#test option:selected').text()

But not working.

 <div class="col-md-10">
     @Html.DropDownList("Percentage", new SelectList(items, new { @class = "form-control", @id = "test" }))
 </div>

And de Js file:

$(document).ready(function () {

$("#test").change(function () {
    var result = $("#test option:selected").text();
    alert(result)     
});

but still, nothing.

1
  • did any error occur? Commented Nov 28, 2019 at 18:36

1 Answer 1

1

You will need to fix your DropDownList. Right now you have your dropdown attributes mixed with your SelectList.

 <div class="col-md-10">
     @Html.DropDownList("Percentage", new SelectList(items), new { @class = "form-control", @id = "test" })
 </div>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.