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

5
  • 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? Commented Jun 17, 2013 at 23:07
  • I need to get the select value to the controller Commented Jun 17, 2013 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? Commented Jun 17, 2013 at 23:12
  • look at this...use a switch statement? stackoverflow.com/questions/1435012/… Commented Jun 17, 2013 at 23:44
  • but how do I get the value in the controller Commented Jun 18, 2013 at 0:09

1 Answer 1

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()
});
Sign up to request clarification or add additional context in comments.

3 Comments

I am not using forms thats why I am using jquery to get result....all I need to know is how to get the jquery result from my jquery to the controller
post using query strings then.
This seems really good but I am getting this as value when passing leagueSelection as string in controller = "' $('"

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.