简体   繁体   English

我可以通过使用按钮传递其他值作为输入,但在MVC3中显示其他内容吗

[英]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. 但是,当我单击按钮时,我想将注释ID 发送/传递给提交的方法。 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. 这是将S.ID传递给控制器​​方法,但这不是很直观,我觉得这不是最好的方法。

Do you need to pass anything else apart from the ID ? 除了ID以外,您还需要传递其他任何内容吗?

If not then you can just use a simple anchor and set the URL to be something like 如果没有,那么您可以使用一个简单的锚并将URL设置为类似

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

and create the method that accepts the ID. 并创建接受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. 或者,您可以使用jQuery对方法进行AJAX调用,然后可以访问button元素上的任何属性,然后在AJAX调用中使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 jQuery MVC3如何从按钮提交传递参数并返回操作结果 - JQuery MVC3 How do I pass a parameter from a button submit and get the action result back 如何使MVC3调用具有不同名称的视图? - How can I get MVC3 to call a view with a different name? 使用asp.net mvc3,如何以不同的格式显示数据如何存储在数据库中? - Using asp.net mvc3, how do I display data in a different format to how it's stored in the database? 单击按钮时如何使用不同的元素值显示/过滤元素的值 - How can i display/filter values of elements, using a different value of an element when a button is clicked 如何在MVC的帮助下使用if else条件传递单个返回值? - How to pass a single return value by using if else condition with the help of MVC? 如何在MVC3中使用剃刀写入输入值 - How to write input value with razor in MVC3 从“轨迹栏”获取值并将此值用于其他用途 - Getting values from 'trackbar' and using this value for something else 来自控制器的MVC3对话框显示 - MVC3 Dialog display from controller 当用户使用MVC3 C#asp.net单击按钮时显示弹出对话框 - Display popup dialog box when user clicks button using MVC3 C# asp.net MVC-如何使用@RenderPage(或其他方式)渲染页面和控制器? - MVC- How can I render a page and the controller with @RenderPage (or with something else)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM