views:

21

answers:

1

Hi all,

Having a little trouble and wondered if anyone could help :-)

I am trying to pass the value that a user enters into a html.Textboxfor to an html.Action link. As shown below :

  <%=Html.TextBoxFor(m => m.OrderQty)%>
        <p class="button" >
            <%: Html.ActionLink("Add to cart", 
                  "AddToCart", 
                  "ShoppingCart", 
                  new { id = Model.Product.ProductId, Qty = Model.OrderQty }, "")%>
        </p>

But when i put a breakpoint in the AddToCart Qty is always 0 :-(

Does anyone have any ideas ?

Thanks John

+1  A: 

I would recommend you using a form instead of an action link. This way the value entered in the textbox will be automatically sent to the server and you don't have to worry about javascript:

<% using (Html.BeginForm("AddToCart", "ShoppingCart", 
    new { id = Model.Product.ProductId, Qty = Model.OrderQty }, 
    FormMethod.Get)) { %>

    <%= Html.TextBoxFor(m => m.OrderQty) %>
    <input type="submit" value="Add to cart" />
<% } %>
Darin Dimitrov