What I am doing is this. I have a basic table with a button at the end of each row for “selection” of that row for further actions. My action method has two simple parameters I’ll call them id1 and id2 so:
public ActionResult DoSomething(int id1, int id2)
id1 will be bound from a hidden form field outside the scope of the table, this works fine.
id2 needs to come from a hidden column from an individual row in the table depending on the button clicked representing the row that requires further processing. Make sense?
When the form posts back to the action method, id1 is set perfectly, no problem, but id2 is always the value of the hidden column from row 1. How do I detect/make DefaultModelBinder pull the hidden column value from the row from which the button is being clicked?
Thanks for the assist as I am actively trying to figure this out.
Here is the hidden table column that is rendered per row that I want to capture it’s value on the post from the row from which the button was clicked:
<td style="display:none;">@Html.Hidden("id2", viewModel.id2)</td>
You could use simple hyper links instead of forms on each row. Like this:
which assuming default routes should generate the following link:
and when you click on it the
DoSomethingaction will be invoked with correct parameters.If you want to do this with POST you will need multiple forms, one for each row: