How to pass value to function using DropDownListFor

Question!

I have a C# web MVC app that has a dropdownlist with 2 items as follows:

Current version Previous version

When the dropdownlist is selected the versionData java script function is currently being called but I can’t seem to get the selected item value passed in the function:

@Html.DropDownListFor(x => x.Items, Model.Items,"",new {ng_model="versionid " , ng_change="VersionData(versionid) })"

Depending on the item selected a value should be passed to the function.

Example : current version: value = v1 Previous version: value = v2

So when the functioning is called it should pass a value like… VersionData(v1)….

How can I achieve this?

By : Milligran


Answers

Why not just get the value in the JavaScript function you are calling using jQuery?

So you could do:

function VersionData() {
    $("DropdownListName").find(":selected").text()
}


This video can help you solving your question :)
By: admin