This is a migrated thread and some comments may be shown as answers.

Pass value to controller?

1 Answer 25 Views
NumericTextBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
jfkrueger
Top achievements
Rank 1
jfkrueger asked on 08 Jun 2012, 04:47 PM
I have the following html:

<tr valign="middle">
    <td>
        @(Html.Telerik().NumericTextBox()                                  
        .Name("Quantity")                                  
        .MinValue(1)                                  
        .Value(1)
        .InputHtmlAttributes( new
            {
                style = "width: 50px"
            } )
        )
    </td>
    <td>
        <a href='@Url.Action( "AddToCart", "ShoppingCart", new {itemId = @Model.InventoryItemId} )'>
            <img id="ImageAddToCart" src="/Content/Images/AddToCart.jpg" style="border-style:none" alt="Add To Cart"/>
        </a>
    </td>
</tr>

As you can see, I am passing the item id of the item I am adding to the cart but I also need to pass the quantity (value of the numeric textbox). How can this be accomplished?

Thanks!




1 Answer, 1 is accepted

Sort by
0
jfkrueger
Top achievements
Rank 1
answered on 08 Jun 2012, 08:46 PM

I did it by using JavaScript like this:

function addToCart(itemId) {
    var numericTextBox = $("#TextBoxQuantity").data("tTextBox");
    var quantity = numericTextBox.value();
    window.location.href = "../ShoppingCart/AddToCart/?itemId=" + itemId + "&quantity=" + quantity;
}

Is this a good way to go or is there a better way?

Thanks!






Tags
NumericTextBox
Asked by
jfkrueger
Top achievements
Rank 1
Answers by
jfkrueger
Top achievements
Rank 1
Share this question
or