Passing a text field value using Html.ActionLink

I have a table that lists products, and also displays a text box for quantity and Html.ActionLink. Each quantity text box has a unique identifier derived from the product identifier. I think this should be simple, but I cannot figure out how to get the value in the linked text field 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>
+5
source share
2 answers

I think you want:

<%= Html.TextBox(String.Format("item[{0}].quantity", item.Id), "0") %>

Take a look at the following Scott Hanselman blog post for more details:

ASP.NET , , ,

. :

ASP.NET MVC

+2

HTML , ASP.NET MVC .

:

  • JavaScript, , , . ASP.NET, .

  • . HTML. , . . URL-, .

+3

All Articles