[英]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.