使用传递文本框的值Html.ActionLink [英] Passing Textbox Value using Html.ActionLink
问题描述
我有,该目录的产品以及显示一个数量文本框和一个Html.ActionLink的表。每个文本框的数量已经从产品ID得出一个唯一的ID。我想这应该是简单,但我似乎无法弄清楚如何当用户点击链接得到传递给我的控制器相关的文本框中的值。我的code低于任何帮助AP preciated。
<%的foreach(在型号VAR项){%GT; &所述; TR>
&所述; TD>
<%= Html.En code(item.Id)%GT;
< / TD>
&所述; TD>
<%= Html.En code(item.Description)%GT;
< / TD>
&所述; TD>
<%= Html.En code(的String.Format($ {0:F},item.Cost))%GT;
< / TD>
&所述; TD>
&所述;%= Html.TextBox(的String.Format(量{0},item.Id),0)%>
< / TD>
&所述; TD>
<%= Html.ActionLink(添加,添加,新{ID = item.Id,数量=?我想在这里数量})%GT;
< / TD>
< / TR>
我觉得你想要的东西是这样的:
<%= Html.TextBox(的String.Format(项[{0}]量,item.Id),0)%GT;
看一看下面的斯科特Hanselman的博客文章了解更多这方面的细节:
<一个href=\"http://www.hanselman.com/blog/ASPNETWireFormatForModelBindingToArraysListsCollectionsDictionaries.aspx\"相对=nofollow> ASP.NET电线格式模型绑定到数组,列表,集合,字典
又见从史蒂夫·桑德森这个博客帖子。它可以让你编辑单品:
在ASP.NET MVC 编辑项目的可变长度列表 -
的http://blog.$c$cville.net/2008/12/22/editing-a-variable-length-list-of-items-in-aspnet-mvc/
I have a table that lists products as well as displays a quantity text box and an Html.ActionLink. Each quantity textbox has a unique id derived from the product id. I think this should be simple but I can't seem to figure out how to get the value in the associated textbox passed to my controller when the user clicks on the link. My code is below and any help is appreciated.
<% foreach (var item in Model) { %>
<tr>
<td>
<%= Html.Encode(item.Id) %>
</td>
<td>
<%= Html.Encode(item.Description) %>
</td>
<td>
<%= Html.Encode(String.Format("${0:F}", item.Cost)) %>
</td>
<td>
<%= Html.TextBox(String.Format("quantity{0}", item.Id), "0") %>
</td>
<td>
<%= Html.ActionLink("Add", "Add", new { id = item.Id, quantity="I want the quantity here?" })%>
</td>
</tr>
I think what you want is this:
<%= Html.TextBox(String.Format("item[{0}].quantity", item.Id), "0") %>
Have a look at the following Scott Hanselman blog post for more details about this:
ASP.NET Wire Format for Model Binding to Arrays, Lists, Collections, Dictionaries
See also this blog post from Steve Sanderson. It will allow you to edit single items:
Editing a variable-length list of items in ASP.NET MVC
http://blog.codeville.net/2008/12/22/editing-a-variable-length-list-of-items-in-aspnet-mvc/
这篇关于使用传递文本框的值Html.ActionLink的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!