MVC Multiple submit buttons on a array of objects

Posted by Kieron on Stack Overflow See other posts from Stack Overflow or by Kieron
Published on 2010-04-20T09:46:32Z Indexed on 2010/04/20 9:53 UTC
Read the original article Hit count: 674

Filed under:
|

Hi,

I've got a list of objects in an MVC view, each with a set of submit buttons - Move up, Move down and Remove.

Using the answer from this question, I can get the button clicked - but I need to know which item it would be operating on.

The problem comes from the fact the input's value attribute is passed back, I need more information than that - i.e. an id.

Below is a snippet of the contents of a for loop, rendering each item.

<ul>
    <li><input type="submit" name="SubmitButton" value="Move-Up" class="linked-content-position-modifier" /></li>
    <li><input type="submit" name="SubmitButton" value="Move-Down" class="linked-content-position-modifier" /></li>
    <li><input type="submit" name="SubmitButton" value="Remove" class="linked-content-modifier" /></li>
    <li><%= Model.Contents[i] %></li>
</ul>

When the form is posted back, I can see that the SubmitButton has a value of either Move-Up, Move-Down or Remove - but no idea which item in the array it's referring too.

Without changing the value to something really ugly, how would I tell which item it's referring to?

© Stack Overflow or respective owner

Related posts about asp.net-mvc-2

Related posts about http-post