Take the 2-minute tour ×

I have a masterpage on which i displays groups that user can access now i want to gets its selected value in many controllers for saving with the records. I want to know if it is possible in asp.net mvc 2 and if not then what is the way around for it

share|improve this question

3 Answers 3

up vote 1 down vote accepted

What you are trying is possible and there are different techniques to achieve it. The best approach would depend on how you are invoking your controller actions. Whether you are using normal hyperlinks, submitting standard <form> or using AJAX. So if you are using standard action links you could add some javascript which binds to the onclick event of each link and adds the selected value of the group. Example:

$(function() {
        // everytime a link is clicked
        // add the value of the selected group to the url
        var selectedGroup = $('#IdOfYourDdl').val();
        if (this.href.indexOf('?') > 0) {
            window.location = this.href + '&selectedGroup=' + selectedGroup;
        } else {
            window.location = this.href + '?selectedGroup=' + selectedGroup;
        // cancel the default action as it doesn't contain the selectedGroup
        // parameter in the request
        return false;

and in your controller action you could have this additional parameter:

public ActionResult Foo(string selectedGroup)

Another example is if you use AJAX you could setup a default data in the master page which will ensure that the value of the dropdown will be sent along each AJAX request you are performing:

    data: { selectedGroup: $('#IdOfYourDdl').val() }

Now whenever you send an AJAX request to your server:

$.get('/foo', { someParam: 'someValue' }, function(result) {


the following request will be sent: /foo?someParam=someValue&selectedGroup=123 so you will be able to fetch the value of the selected group back in the controller action.

share|improve this answer

I hope I understand your question since no code-example is supplied. You can do this using a viewmodel on the page which contains your display groups. Another option is to get the value from the FormCollection when the page is posted.

For example:

public ActionResult MyAction(MyViewmodel viewModel)
//value from your viewmodel, strongtype
var value = viewModel.group;


public ActionResult MyAction(FormCollection collection)
//value as a string
var value = collection.getValue("MyKey").AttemptedValue;

If this answer doesn't statisfy you then please be more clear in your question and i'll try to help you further.

share|improve this answer

As long as your drop down list is a descendant of the <form> that is submitted, it will be subjected to standard model binding, which means you can include it as a parameter on your action. Ensure the name attribute of the drop down list matches the name of the action parameter.

Final rendered HTML:

<form action="http://.../MyAction" method="post">
  <select name="dropDownList">


public ActionResult MyAction(string dropDownList, MyActionModel model)
    // dropDownList = value attribute of selected <option>
share|improve this answer

Your Answer


