0

I'm trying to build a table where you can see the current state of a person (which is loaded from a database) in MVC3. The user have an option to change and set the status, which is saved to the database. As an example:

Example

I'm very new to MVC3 and I'm not sure how to take the value of the dropdown menu to the controller.

My code for displaying the dropdownmenu/Set button is as follows:

<td>
    <%= Html.DropDownList("Statuses",new SelectList(ViewData.Model.Statuses))%>
    <a href="/People/Set" class="btn btn-primary">Set</a>
</td>

I managed to get the Set button to call a method in the "PeopleController," but I'm not sure how to:

  1. pass in the value from the dropdownlist
  2. ensure i'm not passing in the value from a wrong dropdownlist (in this example there are 3 dropdown lists).
  3. I have to ensure that I'm changing the status of the correct person - each person has a unique name, and I can change the correct Status if I know the name of the person.

Note:I'm using MVC3.

3
  • Change the set link to a submit button. Wrap the ddl and button in a form. Write a post method in your controller to process the data Commented Mar 12, 2013 at 16:39
  • @Forty-Two How can I get the id(name) of the person? the id is displayed on the same row as such: ID | Status| Change Status To Commented Mar 12, 2013 at 17:51
  • You can put a hidden field with the id in the form as well Commented Mar 12, 2013 at 17:53

1 Answer 1

1

To summarize and clarify my comments above, Wrap the dropdownlist in a form, make the Set link a submint button, and add a hidden element to pass the Id along as well.

    <td>
        <% using(Html.BeginForm())
        {%>
           <%=Html.DropDownList("Statuses",new SelectList(ViewData.Model.Statuses))%>
           <%=Html.Hidden("Id")
           <input type="submit" value="Set" />
        <%}%>
    </td>

(ps, consider making the leap to the razor view engine, it's much nicer to read and write)

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.