views:

289

answers:

2

Instead of a grid with an 'Edit' link in each row, I'd like to use a drop down list and a single 'Edit' button. What's the cleanest way to make that button direct to /Edit/{id}(i.e. the ddl selected value)? Using onclick with window.location is way too ugly, super ugly if I have to account for the url base being http://approot/ or http://approot/controllername/ since it's on the Index view.

+1  A: 

You can always use simple html form with dropdown and submit button.

LukLed
Thank you. This actually lead me down a nice learning path. But ultimately, curtisks answer squeezed the juice out of my mind grapes.
Jason Kostempski
+1  A: 

You can use any kind of form presentation, you just have to make sure the name of the value you're submitting matches the type and name what the controller is expecting.

For example on the page:

<select id="userList" name="userList">
<option value=1>My Name</option>
<option value=2>Your Name</option>
</select>

and then the controller that the form is talking to should look something like:

public ActionResult Edit(int userList){......

then whatever option was selected will pass its value to the controller, as long as the names match and the form's action is the correct controller action

curtisk
I like this method. Just to clarify, because it wasn't obvious to me that I could do this right away, I had to specify the action and controller in <% Html.BeginForm("Edit", "Home"); %> to make the form, which was on the Index view, post to the Edit action.
Jason Kostempski
@Jason Kostempski: It would be more RESTful if you used `<% Html.BeginForm("Edit", "Home", FormMethod.Get); %>` to start editing.
LukLed