0

How can I get the selected value from a drop down list in mvc from jquery to the controller.

View:

<tr><td>Choose League: </td><td><select name="leagueSelection" id="leagueIdDrop" class="dropdownlistLeagueStyle"><option value="1">Barclays Premier League</option><option value="6">Bundesliga</option><option value="7">Seria A</option><option value="8">Ligue 1</option><option value="9">La Liga</option><option value="10">Eredivisie</option></select></td><td><input id="leagueButton" class="loginButton" value="GetTeams" type="submit" /></td></tr>

I need to get the selected value so I can pass through the get teams method parameter

BuyMy Bet
  • 3
  • 1
  • 6
  • Please state your intentions better. So the user selects a value in the list, now what happens? What do you expect to happen for the user? What existing code do you have? – Styxxy Jun 17 '13 at 23:07
  • I need to get the select value to the controller – BuyMy Bet Jun 17 '13 at 23:10
  • Please explain how the flow on your page is. The flow of the user! You just repeat what you have stated before. The action, should it happen after a button push? Is it a form submit? Is it an AJAX call? – Styxxy Jun 17 '13 at 23:12
  • look at this...use a switch statement? http://stackoverflow.com/questions/1435012/switch-statement-in-jquery-and-list – ewizard Jun 17 '13 at 23:44
  • but how do I get the value in the controller – BuyMy Bet Jun 18 '13 at 00:09

1 Answers1

3

based on the name attribute of your select, you will want to have a parameter named "leagueSelection" in you controller's action. Assuming that your select is contained within a form element that posts to controller name/Submit.

public ActionResult Submit(int leagueSelection)
{
    // do what ever you want
}

you can also post with query string parameters

$.ajax({
  type: 'POST',
  url: '/controller/submit?leagueSelection=' + $('#leagueIdDrop').val()
});
jcwmoore
  • 1,153
  • 8
  • 13