简体   繁体   中英

Can I pass a different value as a input from using button but display something else in MVC3

I have a list of button which has to display the number of comments as the value of the button. But when I click the button I want to send/pass the comment Id to the method that is submitted. Is there a way to achieve this kind of thing?

Edited: What I did was, In the table That I have list of buttons

                @foreach(var s in Model.List)  
                 {
                    <tr>
                        <td style="text-align:left;">@s.ID</td>
                        <td style="text-align:center;">@s.CD</td>
                        <td style="text-align:center;">@s.DE</td>
                        <td style="text-align:center;">                                
                            <input class="xxxxx" style="text-align:center;" type="submit" name="count" value ="@s.k" />
                            <input type="hidden" name="SupportID" value="@s.ID" />                                                            
                        </td>
                    </tr>
                  }

This is passing the S.ID to the controller method, But it is not intuitive and I feel that is not the best method to do it.

Do you need to pass anything else apart from the ID ?

If not then you can just use a simple anchor and set the URL to be something like

href="/Page/Method/@s.ID"

and create the method that accepts the ID.

Alternatively you can use jQuery to do an AJAX call to the method, you will then have access to any attributes on the button element to then use in the AJAX Call.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM